mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2009-04-29, 11:15   #1
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

22×5×373 Posts
Default Linux weirdness; Help?

Consider the following code snippet:

scanf("%s", filename)
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC);


Under AIX, the open call picks up the default file permissions
from the shell umask. In Linux, everytime I open a new file,
*using the same code* the file permissions are DIFFERENT!!
Sometimes they even come out as 000! Sometimes the sticky
bit is lit for one or more fields. Sometimes the permissions come
out as 050, sometimes as 400, etc. etc.

Can anyone explain this? I can of course do an explicit fchmod()
on the file, but I need an understanding of the current weirdness.
R.D. Silverman is offline   Reply With Quote
Old 2009-04-29, 12:22   #2
Chris Card
 
Chris Card's Avatar
 
Aug 2004

2·5·13 Posts
Default

Quote:
Originally Posted by R.D. Silverman View Post
Consider the following code snippet:

scanf("%s", filename)
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC);


Under AIX, the open call picks up the default file permissions
from the shell umask. In Linux, everytime I open a new file,
*using the same code* the file permissions are DIFFERENT!!
Sometimes they even come out as 000! Sometimes the sticky
bit is lit for one or more fields. Sometimes the permissions come
out as 050, sometimes as 400, etc. etc.

Can anyone explain this? I can of course do an explicit fchmod()
on the file, but I need an understanding of the current weirdness.
Not sure, but the man page for open() says:

mode specifies the permissions to use in case a new file is cre-
ated. This argument must be supplied when O_CREAT is specified
in flags; if O_CREAT is not specified, then mode is ignored.
The effective permissions are modified by the process’s umask in
the usual way: The permissions of the created file are
(mode & ~umask). Note that this mode only applies to future
accesses of the newly created file; the open() call that creates
a read-only file may well return a read/write file descriptor.

so it may well be that behaviour is random if you supply O_CREAT but no mode.

Chris
Chris Card is offline   Reply With Quote
Old 2009-04-29, 12:25   #3
akruppa
 
akruppa's Avatar
 
"Nancy"
Aug 2002
Alexandria

2,467 Posts
Default

If you specify O_CREAT, you must supply the mode as third argument to open(), or whatever value is on the stack/in the corresponding register becomes your mode.

Alex
akruppa is offline   Reply With Quote
Old 2009-04-29, 12:35   #4
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

164448 Posts
Default

Quote:
Originally Posted by akruppa View Post
If you specify O_CREAT, you must supply the mode as third argument to open(), or whatever value is on the stack/in the corresponding register becomes your mode.

Alex

Ah. The man pages that I have (RedHat V5 on IBM platform) does
not say that the third argument is NECESSARY.
R.D. Silverman is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kaby Lake / Asrock disappointment, RAM weirdness Prime95 Hardware 17 2017-01-27 21:09
AVX2 weirdness bsquared Programming 1 2016-01-17 17:26
Achievement? No, just weirdness R.D. Silverman Lounge 5 2015-05-14 22:27
More Weirdness R.D. Silverman Programming 4 2009-05-24 22:01
Benchmark Weirdness R.D. Silverman Hardware 2 2007-07-25 12:16

All times are UTC. The time now is 14:23.


Tue Aug 3 14:23:07 UTC 2021 up 11 days, 8:52, 1 user, load averages: 4.61, 4.02, 3.84

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.