Re: umask of files created in COMPILE_DIR

"Larry Leszczynski" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
Hi Todd -

> I'm not seeing a umask being applied when File::Temp creates the file:
> 
> $ umask
> 0002
> $ perl -MFcntl -e 'sysopen(my $fh, "./sysopened", O_WRONLY | O_APPEND | O_CREAT, 0600)'
> $ ls -l
> -rw-------  1 me  me  0 Sep  9 10:35 sysopened

It is being applied, it just doesn't do anything.  sysopen creates the
file as 0600.  umask 0002 means "remove o=w permissions", which the file
does not have in the first place, so the permissions stay as 0600.


Try changing your umask to 0222 and do the same test:

$ rm sysopened
$ umask 0222
$ umask
0222
$ perl -MFcntl -e 'sysopen(my $fh, "./sysopened", O_WRONLY | O_APPEND |
O_CREAT, 0600)'
$ ls -l sysopened 
-r--------  1 larry  staff  0 Sep  9 12:15 sysopened

sysopen creates the file as 0600.  umask 0222 means "remove u=w, g=w,
o=w permissions", so the permissions change to 0400.


> If I take out the 0600 from the sysopen call, then the file gets g+r,g+w

As expected.  According to
http://perldoc.perl.org/functions/sysopen.html:

   If you omit the PERMS argument to sysopen, Perl uses the octal value
   0666.

sysopen creates the file as 0666.  umask 0002 means "remove o=w
permissions", so the permissions change to 0664.


HTH,
Larry
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.