11

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.

2 Answers 2

12

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--).
4

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 .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.