0

I have a Raspberry Pi 3 on which I use Visual Studio cross-platform building to build an application (.out) file. The (.out) file has permissions for everyone. When I run this (.out), it creates a folder on the Pi to save some text files with some output data. However, when I try to open the folder to access the data, it gives me the error "Error opening ... Permission Denied". For some reason, the permission of the output folder is "Owner Only". I have to use "chmod" every time to change the permission, which is inconvenient. The strange thing is that I have other Pi units with the same ".out" but the files are accessible, and no permission issue. I tried to install a new OS image on this specific unit, but same issue. Any thoughts?

Edit: Here is the code I use to create the output folder

    if (mkdir(outputdir_time_tagged, 0700) == 0)
        printf("[INFO_] Output directory created successfully\n");
2

2 Answers 2

0

Unless you specifically set the permissions in your program, the UMASK is used.

You can set the UMASK globally in /etc/pam.d/common-session. You can set the UMASK for your current session with

umask 007

or even for a specific command:

(umask 002 &&  a.out)
1
  • I did an edit to the question and added the code snippet I use to write the output folder Jan 13, 2023 at 18:31
0

I figured out that the permissions in my command could be changed to solve the issue. The permission I used 0700 is only for "owner". On the Raspberry Pi I was working on, "root" was the owner and not my user account. Changing the permission to 777 ensured that "anyone" permissions were set. Since "mkdir" is affected by "umask" as Ljm Dullaart mentioned in his answer, I added "chmod" to ensure the required 777 permission is applied regardless of the "umask" value.

if (mkdir(outputdir_time_tagged, 0777) == 0)
    chmod(outputdir_time_tagged, 0777);
    printf("[INFO_] Output directory created successfully\n"); 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .