newbie00 has asked for the wisdom of the Perl Monks concerning the following question:

Hello and Happy Holidays.

Does changing 'umask' change the system's default value or does it only apply for the current code and does not affect the system's default value?

Also, what is the result of the 'mkdir' on the directory created if the mode that is specified is different than the default 'umask' if the 'umask' statment is not used in the code?

What I mean is, if e.g.

mkdir("dirname", 0777) or die "could not create dir: $!";
...when the umask default is 0755. Will the new directory, 'dirname' have the permissions of 0755 or 0777?

If the code is...

umask 022; mkdir("dirname", 0777) or die "could not create dir: $!";
...Will the system's default permission be changed from 0755 to 0777 due to these statements? (will subsequent directories created have permissions of 0777 or will the default still be 0755)?

What code do I use if I just want to create a directory with the system's default mode?

I hope this is clear. Most references I read are very vague on the use of 'umask'. I don't want to use it incorrectly and change the system's default. The hosting company may not appreciate it, so I need enough info (risks; proper use; when to use; etc.) before proceeding.

Thanks.
--newbie00

Replies are listed 'Best First'.
Re: Does changing 'unmask' change the system's default value?
by VSarkiss (Monsignor) on Dec 25, 2001 at 01:22 UTC

    First, it's not "unmask", it's umask (no N). You can read more about the Perl version here.

    As to your direct question, the umask is set on a per-process basis. There's no "system umask", only what is set by your administrator in user startup files. If you set the umask, it will affect all files (and hence directories) created after that point by that process. In systems I know, the umask is inherited by child processes, but I'm not sure if that's true of all Unix-oid systems or not. It's certainly not true of Win32 systems, and I can't really speak to how it's implemented there.

    HTH

      Hello and thanks for your reply. I am referring to a UNIX box.

      I'm not sure why I have 'uNmask' stuck in my head but I did mean 'umask'.

      Question: What do you mean by 'per-process basis'? I want to be real sure how long the changing of 'umask' will last.

      Is 'per-process' a session (duration of the script -- for all directories and files created until the script ends) or is it 'permanent' until it is changed again OR am I changing the value that the admininstrator set for my hosting account?

      Thanx.
      --newbie00

        Per-process means a single invocation of a program (or script). In other words, once you change it, it will affect files created after that point by that program, and (possibly) child processes created by that program. It will not affect any other programs or users, nor will it be remembered after the program ends.

        HTH