summaryrefslogtreecommitdiff
path: root/src/lib/shm_ap_rbuff.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-09-07 14:53:19 +0200
committerdimitri staessens <[email protected]>2016-09-07 14:53:19 +0200
commita92a55f2489820f030f461ebc09d621b001a01df (patch)
treebea8fe98f0809d856a243e8485535fe7ac993808 /src/lib/shm_ap_rbuff.c
parent8ec02f772f3530d5c9023bd1ccf74fea555c69ed (diff)
downloadouroboros-a92a55f2489820f030f461ebc09d621b001a01df.tar.gz
ouroboros-a92a55f2489820f030f461ebc09d621b001a01df.zip
lib: Set umask for file creation permissions
Permissions are now set correctly upon creation, removing the need to call fchmod.
Diffstat (limited to 'src/lib/shm_ap_rbuff.c')
-rw-r--r--src/lib/shm_ap_rbuff.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c
index e6665362..473894d5 100644
--- a/src/lib/shm_ap_rbuff.c
+++ b/src/lib/shm_ap_rbuff.c
@@ -75,6 +75,7 @@ static struct shm_ap_rbuff * shm_ap_rbuff_create(bool dir)
pthread_mutexattr_t mattr;
pthread_condattr_t cattr;
char fn[FN_MAX_CHARS];
+ mode_t mask;
if (dir == SOUTH)
sprintf(fn, SHM_AP_RBUFF_PREFIX "south.%d", getpid());
@@ -87,6 +88,8 @@ static struct shm_ap_rbuff * shm_ap_rbuff_create(bool dir)
return NULL;
}
+ mask = umask(0);
+
shm_fd = shm_open(fn, O_CREAT | O_EXCL | O_RDWR, 0666);
if (shm_fd == -1) {
LOG_DBG("Failed creating ring buffer.");
@@ -94,11 +97,7 @@ static struct shm_ap_rbuff * shm_ap_rbuff_create(bool dir)
return NULL;
}
- if (fchmod(shm_fd, 0666)) {
- LOG_DBG("Failed to chmod shared memory.");
- free(rb);
- return NULL;
- }
+ umask(mask);
if (ftruncate(shm_fd, SHM_RBUFF_FILE_SIZE - 1) < 0) {
LOG_DBG("Failed to extend ringbuffer.");