Linux: Getting Umask of an Already Running Process

linux: getting umask of an already running process?

You can attach gdb to a running process and then call umask in the debugger:

(gdb) attach <your pid>
...
(gdb) call umask(0)
[Switching to Thread -1217489200 (LWP 11037)]
$1 = 18 # this is the umask
(gdb) call umask(18) # reset umask
$2 = 0
(gdb)

(note: 18 corresponds to a umask of O22 in this example)

This suggests that there may be a really ugly way to get the umask using ptrace.

How can I set the umask of a process I am spawning?

Since the preexec_fn argument seems to work for you, you can use it to call os.umask() as well:

def initchildproc():
os.setpgrp()
os.umask(400)

subprocess.Popen(cmd, shell=False, preexec_fn=initchildproc, ...)

How to know current mask

Is there a way to do the same in C?

I've got some bad news for you, you can't do it in C. But, then again, you can't really do it in bash either :-)

The bash shell itself uses the "change it then quickly change it back" method for getting it, which you can also do from your own C program:

mode_t umask_arg;
umask_arg = umask (022); // get it while temporarily setting.
umask (umask_arg); // change it back quickly.
// umask_arg now has the umask.

Other than my added comments, that's directly from builtins\umask.def (which creates the file to eventually be compiled for the umask built-in) in version 5.1 of the bash shell.

Setting the umask of the jenkins process

Set the umask by configuring the daemon, just add --umask=002 to the daemon args in /etc/init.d/jenkins:

DAEMON_ARGS="--name=$NAME --inherit --env=JENKINS_HOME=$JENKINS_HOME --output=$JENKINS_LOG --pidfile=$PIDFILE --umask=002"

Setting the umask of the Apache user

Apache inherits its umask from its parent process (i.e. the process starting Apache); this should typically be the /etc/init.d/ script. So put a umask command in that script.

Set umask permissions new branches on git

Try first to initiate your local Git repo with:

git init --shared=group 

That would be more reliable than umask.

git init --shared:

Specify that the Git repository is to be shared amongst several users.

This allows users belonging to the same group to push into that repository.

When specified, the config variable "core.sharedRepository" is set so that files and directories under $GIT_DIR are created with the requested permissions.

When not specified, Git will use permissions reported by umask.



Related Topics



Leave a reply



Submit