fopen fails when file exists

c, file-permissions, fopen, linux

Solution

`fopen` creates files with permission `0666` modified by the process's `umask`.

So if you do not manually change the files permissions within your program or after your program has finished.

The process will most likely have a wrong umask.

Do you set the `umask` within your programm or within the context of the calling process? Your `umask -S` output actually looks fine (looks like umask `002`).

Problem

I have the following snippet of code running inside a massive Linux daemon. I'm trying to debug to a log file, but when the log file exists, the `fopen` fails ``` if ( ( debugFILE = fopen( "/home/lala/debug.log", "a" ) ) == NULL ) { perror("error: "); } ``` The error I get is: "Permission denied". This is a the output of ls of the specific file: ``` ----rw---- 1 lala lala 0 Mar 11 18:26 debug.log ``` First, why the file was created in the firstplace with these permissions. Second, why the fopen succeeds when creating, but not when opening ?

Original source