Consider the following C program:
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/types.h>
#include <string.h>
int main() {
const char* name = "/memmap_ipc_shm";
int shmFd = shm_open(name, O_RDWR | O_CREAT, 0777);
if (shmFd < 0) {
fprintf(stderr,"bad shmfd opening %s: %s\n", name, strerror(errno));
return -1;
}
return 0;
}
When I run it on my GNU/Linux system (Devuan Beowulf, Linux 5.10.0-9, amd64 CPU), I get:
bad shmfd opening /memmap_ipc_shm: Permission denied
Why am I denied permission? I'm pretty sure I followed all the guidelines in the man shm_open
page, my requested permissions seem ok - so what's wrong?