[PATCH v2] procfs: expose umask in /proc/<PID>/status
From: Richard W.M. Jones
Date: Thu Apr 14 2016 - 07:08:31 EST
v1 -> v2:
- Change printf format to %#04o.
- Retest and update examples accordingly.
----------
It's not possible to read the process umask without also modifying it,
which is what umask(2) does. A library cannot read umask safely,
especially if the main program might be multithreaded.
Add a new status line ("Umask") in /proc/<PID>/status. It contains
the file mode creation mask (umask) in octal. It is only shown for
tasks which have task->fs.
For the library this allows me to read the umask from
/proc/self/status.
This patch is adapted from one originally written by Pierre Carrier:
https://lkml.org/lkml/2012/5/4/451
Example usage:
$ grep Umask /proc/1/status
Umask: 0022
$ grep Umask /proc/2/status
Umask: 0022
$ grep Umask /proc/self/status
Umask: 0022
$ umask 002
$ grep Umask /proc/self/status
Umask: 0002
Rich.