1823920 Members
3137 Online
109667 Solutions
New Discussion юеВ

setting umask value

 
SOLVED
Go to solution
sheevm
Regular Advisor

setting umask value

Hi,

One of the app developer is trying to aet umask value in his script to uamsk 077. But after running his profile, umask is still showing 022 default value.

The purpose is, the files created by this user must have umask of 077 (just for this user)

Can someone help?

Thanks
Rajim

be good and do good
7 REPLIES 7
Steven E. Protter
Exalted Contributor

Re: setting umask value

Shalom,

The developer could just type:
umask 077

At the command prompt.

Developers being developers, you'll need to modify his/her profile.

Start with /etc/profile and then .profile and try to make this statement the last thing that happens when the profile gets sourced.

umask 077

Have a great day.

And ask yourself, what have you done to enable a helpless developer today.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: setting umask value

Hi:

Given:

# cat ./mymask
umask 077

...if you do:

# ./mymask

...then the umask of your current environment will remain *unchanged*.

If you source (read) the script as:

# . ./mymask

...then the changed umask will be propogated and changed in the current environment.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: setting umask value

If your app developer doesn't understand the concept of child processes not being able to alter a parent processes environment then I'm not sure that this app developer should be developing apps yet. He is indeed setting umask but as soon as that process terminates and control is returned to the parent process, umask is exactly back to where it was.

There are really two options:
1) explicitly set umask in .profile
2) His script should be sourced in .profile by using the dot "." operator; sourcing a file makes the file part of the foreground process so that a child process is not involved. This sourced file must not contain an exit or return statement as that would have the effect of exiting the foreground process (the shell in this case).
If it ain't broke, I can fix that.
sheevm
Regular Advisor

Re: setting umask value

Hi,

I tested this. The directory permission are O.K with the new umask 077. But if I touch file in that directory it does not have the same umask

Raji
be good and do good
A. Clay Stephenson
Acclaimed Contributor

Re: setting umask value

Okay, let's do this:

umask 077
mkdir mynewdir
cd mynewdir
touch mynewfile
ls -l

I suspect that you will find that '.' the local directory has mode 700 (drwx------) and that mynewfile has mode 600 (-rw------) which is entirely consistant with a umask of 077.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: setting umask value

I suspect what is confusing you is that with a umask of 077, directories are created with 700 permissions but regular files are created within the shell with 600 permissions. There are two things at play here: 1) the default creation mode of the file, and 2) the umask value. Umask "subtracts" from the creation mode to yield the effective mode. The operation isn't really subtraction; it's a NAND but you can kinda, sorta think of it as subtraction. The default creation mask for directories is 777 and the default creation mask for regular files is 666 and therefore the observed results make perfect sense.
In order to set the execute bit from within the shell, an explicit chmod is required after the file is created. In other languages (e.g. C,C++, or Perl) a one-step file creation with execute bit set is possible.
If it ain't broke, I can fix that.
sheevm
Regular Advisor

Re: setting umask value

Thanks. Just umask setting does not help the developr really. He has to use the chmod on the file.

Thanks again
be good and do good