[ILUG] umask query
Sean O Sullivan
seanos at netsoc.itcarlow.ie
Sat Apr 23 11:37:16 IST 2005
Brian Foster wrote:
> | Date: Fri, 22 Apr 2005 19:11:52 +0100
> | From: Sean O Sullivan <seanos at netsoc.itcarlow.ie>
> | Need files and directories to be created with permissions '775'.
> | umask should then be set to '002', however, apparently when set umask
> | it is set, it will dictate that directories will be created as '775',
> | however files as '644' (with a umask of 002).
> that is not quite correct. or at least it appears you
> may believe the umask can do something that it cannot
> actually do, and was not designed to do.
> the umask(2) _clears_ (sets to 0) unwanted permissions
> bits _specified_ by the creating open(2) (for files)
> or mkdir(2) (for directories). so, if yer file is
> being created by:
> open("file", O_CREAT|..., 0666)
> as is usually the case --- 0666 is almost always the
> mode specified (for files, 0777 for directories) ---
> it is absolutely _impossible_ for the umask to cause
> any of the eXecute bits (0111) to be set (for files).
> the umask can cause any of the specified 0666 bits to
> be cleared. e.g., for yer example umask of 002, that
> bit would be cleared resulting in 0664 (rw-rw-r--),
> as you have observed.
> | This is a problem, as I need both to be 775...
> | Is there any solution for this ?
> either chmod(2)/fchmod(2) the file after creation,
> or change the permissions specified in the creating
> open(2). I suggest fchmod since that will make you
> independent of the umask, which it seems is what
> you are really after. either solution does imply
> modifying the source code.
Yes, I realised that umask didn't/couldn't do what I needed - and Colm
mensioned similar to above last night - however I have already stated
chmod etc isn't exactly an acceptable long-term solution.
More information about the ILUG