I am writing a simple C program to exchange messages
through named pipes on linux. The problem is I have
to run it as superuser to make it work, otherwise i get:
“Permission denied” error.
Write permission on the directory is granted:
drwxr-xr-x 2 alpa alpa 4096 26 giu 17.24 .
Umask should be ok:
$ umask
0022
The pipe file is actually created, but with wrong permissions bits:
$ ls -l | grep fifo.fifo
pr----x--t 1 alpa alpa 0 26 giu 17.29 fifo.fifo
So when I try to open it for reading or writing the
open() system call fails.
Here is the code:
...
if(mkfifo(pathname, perms) == -1 && errno != EEXIST)
return NULL;
if(chmod(pathname, perms) == -1)
return NULL;
...
fifo->fd[0]= open(fifo->pathname, O_RDONLY);
if(fifo->fd[0] == -1){
fifo_delete(&fifo);
return NULL;
...
Thank you in advance for your help.
The value that you are passing is decimal
666, which corresponds to octal01232(01210after applying~umask).You should be passing either
0666, or decimal438.