ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Within a C++ program, I am creating a new directory to store log files. The problem is that when I use this code ...
mkdir("logs",0777);
The created directory has it's permissions set to 755. This is catastrophic for my application as the logs directory is shared by all users on the system, and once the logs are initially created by the first user, no other user is able to enable logging.
I am hoping to avoid the need to create a separate logs directory for each user, as this will require substantial modification of the code I'm porting (It was originally a Windows application).
I need to avoid use of the system() function. Also, there is no sensitive information being stored in the logs folder that needs to be kept secret. It is merely diagnostic data to assist in error handling.
I'm not sure you can throw octal at it like that when setting the permission bits. I'm not sure you can't, either, but try ORing the permission bits, like
mkdir("logs", S_IRWXU | S_IRWXG | S_IRWXO );
Another thought is that perhaps the umask is being applied after the directory is being created. If the above does not work, trying temporarily resetting umask to 000.
Thanks, it was fixed by a call to umask(0). I'd never encountered that function before, and had trouble finding documentation on it. I also changed the permissions to S_IRWXU | S_IRWXG | S_IRWXO instead of 0777. This was another problem of not being able to find any documentation on what flags were used by mkdir. Once I read that S_IRWXU ... I knew exactly where to look.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.