From a92a55f2489820f030f461ebc09d621b001a01df Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 7 Sep 2016 14:53:19 +0200 Subject: lib: Set umask for file creation permissions Permissions are now set correctly upon creation, removing the need to call fchmod. --- src/lib/lockfile.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/lib/lockfile.c') diff --git a/src/lib/lockfile.c b/src/lib/lockfile.c index 75ee2085..81bed687 100644 --- a/src/lib/lockfile.c +++ b/src/lib/lockfile.c @@ -43,10 +43,13 @@ struct lockfile { }; struct lockfile * lockfile_create() { + mode_t mask; struct lockfile * lf = malloc(sizeof(*lf)); if (lf == NULL) return NULL; + mask = umask(0); + lf->fd = shm_open(LOCKFILE_NAME, O_CREAT | O_EXCL | O_RDWR, 0666); if (lf->fd == -1) { LOG_DBGF("Could not create lock file."); @@ -54,11 +57,7 @@ struct lockfile * lockfile_create() { return NULL; } - if (fchmod(lf->fd, 0666)) { - LOG_DBGF("Failed to chmod lockfile."); - free(lf); - return NULL; - } + umask(mask); if (ftruncate(lf->fd, LF_SIZE - 1) < 0) { LOG_DBGF("Failed to extend lockfile."); -- cgit v1.2.3