Shared mem bugfix 3

This commit is contained in:
2020-12-28 13:55:38 +01:00
parent 09b2118863
commit 161952441d

View File

@ -153,21 +153,12 @@ int cache_init() {
return -1;
}
int shm_id = shmget(SHM_KEY, FILE_CACHE_SIZE * sizeof(cache_entry), IPC_CREAT | IPC_EXCL);
int shm_id = shmget(SHM_KEY, FILE_CACHE_SIZE * sizeof(cache_entry), IPC_CREAT | IPC_EXCL | 0600);
if (shm_id < 0) {
fprintf(stderr, ERR_STR "Unable to create shared memory: %s" CLR_STR "\n", strerror(errno));
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));