#37 lock_file_create: Set and reset umask before and after creating the lockfile
Opened 3 years ago by jhrozek. Modified 3 years ago
jhrozek/libuser umask_mkstemp  into  master

file modified
@@ -287,11 +287,14 @@ 

  	char pid_string[sizeof (pid_t) * CHAR_BIT + 1];

  	int fd;

  	gboolean ret = FALSE;

+ 	mode_t old_umask;


  	lock_filename = g_strconcat(filename, ".lock", NULL);

  	tmp_filename = g_strdup_printf("%s.lock.XXXXXX", filename);


+ 	old_umask = umask(0177);

  	fd = mkstemp(tmp_filename);

+ 	umask(old_umask);

  	if (fd == -1) {

  		lu_error_new(error, lu_error_open,

  			     _("error opening temporary file for `%s': %s"),


This is not a big deal, but static analyzers are happier when umask is
set explicitly.

OTOH see https://bugzilla.redhat.com/show_bug.cgi?id=908786 , modifying umask in a library called from a possibly-threaded program is problematic.

(I don’t have a better answer though; both doing this and not doing this is wrong.)

I was sort of expecting this answer :) I'm actually more inclined to close this PR and the issue and just maintain the status quo. The issue is not a big deal anyway IMO.