The following line in my C program should provided All/Group/Owner read and write permissions
mkfifo("/tmp/dumbPipe", 0666)
But once I execute the code and check out the permission non of the write bits were set, I end up with
prw-r--r--
The owners are the same, Is it a problem since I'm creating the pipe in the tmp directory? When I run chmod 666 from the cmd line all the permissions get set correctly.
This is a no-comments post, just quoting manuals. Brievity etc.
Quote from man 3 mkfifo:
It is modified by the process's umask in the usual way: the permissions of the created file are (mode & ~umask).
Quote from man 2 umask
The typical default value for the process umask is S_IWGRP | S_IWOTH (octal 022). In the usual case where the mode argument to open(2) is specified as:
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH (octal 0666) when creating a new file, the permissions on the resulting file will be: S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH (because 0666 & ~022 = 0644; i.e., rw-r--r--).
Salam, I know it is to late but for other users I choose to write this comment Even if you precise 0666 as permission, you should know that there is an another factor that is called " process's file mode creation ", so the question is :
how to change current process file mode creation ?
Answer : use umask(permission) at beginning of your program - and give 0000 as permission
http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html
this should help .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With