From 09b211886359057ebd815a9facea47261f15ccaf Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Mon, 28 Dec 2020 13:53:18 +0100 Subject: [PATCH] Shared mem bugfix 2 --- src/cache.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cache.c b/src/cache.c index ff86991..95af277 100644 --- a/src/cache.c +++ b/src/cache.c @@ -36,15 +36,6 @@ int cache_process() { return -1; } - struct shmid_ds info; - if (shmctl(shm_id, IPC_STAT, &info) < 0) goto shmctl_err; - info.shm_perm.mode = 0600; - if (shmctl(shm_id, IPC_SET, &info) < 0) { - shmctl_err: - fprintf(stderr, ERR_STR "Unable to update permissions for shared memory: %s" CLR_STR "\n", strerror(errno)); - return -3; - } - shmdt(cache); void *shm_rw = shmat(shm_id, NULL, 0); if (shm_rw == (void *) -1) { @@ -168,6 +159,15 @@ int cache_init() { return -2; } + struct shmid_ds info; + if (shmctl(shm_id, IPC_STAT, &info) < 0) goto shmctl_err; + info.shm_perm.mode = 0600; + if (shmctl(shm_id, IPC_SET, &info) < 0) { + shmctl_err: + fprintf(stderr, ERR_STR "Unable to update permissions for shared memory: %s" CLR_STR "\n", strerror(errno)); + return -6; + } + void *shm = shmat(shm_id, NULL, SHM_RDONLY); if (shm == (void *) -1) { fprintf(stderr, ERR_STR "Unable to attach shared memory (ro): %s" CLR_STR "\n", strerror(errno));