1827328 Members
5779 Online
109962 Solutions
New Discussion

Umask Question.

 
SOLVED
Go to solution
brian_31
Super Advisor

Umask Question.

Hi Team:

We are going to set up umask of 022 in /etc/profile But we have some applications write to /var/tmp and some to /opt/data. The files/directories under these directories should worl writable.
1. How would i achieve this
2. How are the umask for startup scripts controlled. I have particular doubt about swagentd.( i think most of them are from /sbin/rc, but some set thier own umask ...like inetd. what is the purpose of that)?

Any thoughts???

Cheers
Brian.
9 REPLIES 9
Daimian Woznick
Trusted Contributor

Re: Umask Question.

The application can set its own umask value. All scripts can be set this way by invoking the umask command. If the application runs with a specific account the profile can be changed for that account. We will need to know how the application starts to determine how the umask can be changed.

Your startup scripts may have a umask value in them or the application may be coded with a change of umask value in it.
ASSIST
Frequent Advisor

Re: Umask Question.

Hi Brian

Each process or aplication that start's in the rc has its own shell

Set the apropiate umask for each of this in the /sbin/init.t/script

Then set the umask 022 in the /etc/profile or in the $HOME/.profile for each user that you want

Joaquin
Deshpande Prashant
Honored Contributor

Re: Umask Question.

HI
If you know which applications (ID) need differnet UMASK, you can use IF..THEN..ELSE structure in /etc/profile do define different UMASK for different users.
You may set the UMASK in users .profile also.

Thanks.
Prashant.
Take it as it comes.
A. Clay Stephenson
Acclaimed Contributor

Re: Umask Question.

You have to handle the non-typical file creations as a special case.

e.g.
savemask=$(umask 000)
echo "Test" > /var/tmp/myfile
umask $savemask #resets umask to original value
(You could also simply do a chmod after creating the file and forget about umask.)

To answer your second question, scripts set their own umasks according to their own needs. This is most often done so that no matter how tightly or loosely umask is set in /etc/profile, the application will perform as expected because umask has been overridden.

One important point is that there are two masks that need to be considered when files are created. 1) The creation mask 2) umask - which clears bits set in cmask. Man 2 creat for details.


If it ain't broke, I can fix that.
brian_31
Super Advisor

Re: Umask Question.

Team:

Any indea how the swagentd gets it umask set for those .sw directory?? Also in clay's message i did not understand the cmask???

Thanks
Brian.
Jeff Schussele
Honored Contributor

Re: Umask Question.

Hi Brian,

Simply put, the cmask is the "deafult" perms assigned to the file being created UNTIL the umask overrides those perms....or doesn't....whatever the case may be.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Umask Question.


Hi Brian:

cmask is the file's creation mask. I suggested that you do a man 2 creat to see what I'm talking about. If you really want to 'know' how something works in UNIX, look at the system calls because ultimately that's how a file creation is going to occur whether initiated from a shell script, Perl, or a COBOL/C/FORTRAN ... program.

In the shell, the default cmask for directories is 777, and for regular files it is 666. Now the bits in umask subtract from the cmask to leave the actual permissions. Have you noticed when you create shell scripts that you have to set the execute bit manually using chmod even if your umask is 000? That's because your script is a regular file and the default cmask is 666.

In C, for example, you can directly set the file's mode when you create the file.
If it ain't broke, I can fix that.
Jeff Schussele
Honored Contributor

Re: Umask Question.

As to swagentd & umasks there, take a look in /usr/sbin at the sw???? commands, most are all linked as one or two programs. If you do the following:
strings swinstall | grep -i mask
you'll see that it uses many calls to mask functions.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
brian_31
Super Advisor

Re: Umask Question.

Thanks Jeff:

But the sigprocmask and the other stuff mentioned there are quite irrelevant to umask is it not. Anyway i could not make out much from that info(strings swinstall|grep -i mask). Can you explain a little further...

Thanks
Brian.