From 8a2de39c0558accf02f3b620c1e946d556705408 Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Mon, 18 Jul 2016 17:10:57 +0200 Subject: [PATCH] umask.2: Provide a rationale for the existence of /proc/PID/status 'Umask' field Signed-off-by: Michael Kerrisk --- man2/umask.2 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/man2/umask.2 b/man2/umask.2 index ba9837024..2e3933cc0 100644 --- a/man2/umask.2 +++ b/man2/umask.2 @@ -117,10 +117,22 @@ inherits its parent's umask. The umask is left unchanged by .BR execve (2). +It is impossible to user +.BR umask () +to fetch a process's umask without at the same time changing it. +A second call to +.BR umask () +would then be needed to restore the umask. +The nonatomicity of these two steps provides the potential +for races in multithreaded programs. + Since Linux 4.7, the umask of any process can be viewed via the .I Umask field of .IR /proc/[pid]/status . +Inspecting this field in +.IR /proc/self/status +allows a process to retrieve its umask without at the same time changing it. The umask setting also affects the permissions assigned to POSIX IPC objects .RB ( mq_open (3),