Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759291AbcDMM6G (ORCPT ); Wed, 13 Apr 2016 08:58:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41430 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758075AbcDMM6E (ORCPT ); Wed, 13 Apr 2016 08:58:04 -0400 From: "Richard W.M. Jones" To: linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, akpm@linux-foundation.org, luto@kernel.org, viro@zeniv.linux.org.uk, mathieu.desnoyers@efficios.com, zab@redhat.com, emunson@akamai.com, paulmck@linux.vnet.ibm.com, aarcange@redhat.com, josh@joshtriplett.org, xemul@parallels.com, sfr@canb.auug.org.au, milosz@adfin.com, rostedt@goodmis.org, arnd@arndb.de, ebiederm@xmission.com, gorcunov@openvz.org, iulia.manda21@gmail.com, dave.hansen@linux.intel.com, mguzik@redhat.com, adobriyan@gmail.com, dave@stgolabs.net, linux-api@vger.kernel.org, gorcunov@gmail.com, fw@deneb.enyo.de Subject: [PATCH v2 0/2] vfs: Define new syscall getumask. Date: Wed, 13 Apr 2016 13:57:50 +0100 Message-Id: <1460552272-15985-1-git-send-email-rjones@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1220 Lines: 49 v1 -> v2: - Use current_umask() instead of current->fs->umask. - Retested it. ---------------------------------------------------------------------- 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. This patch series adds a trivial system call "getumask" which returns the umask of the current process. Another approach to this has been attempted before, adding something to /proc, although it didn't go anywhere. See: http://comments.gmane.org/gmane.linux.kernel/1292109 Another way to solve this would be to add a thread-safe getumask to glibc. Since glibc could own the mutex, this would permit libraries linked to this glibc to read umask safely. I should also note that man-pages documents getumask(3), but no version of glibc has ever implemented it. Typical test script: #include #include #include #include int main(int argc, char *argv[]) { int r = syscall(329); if (r == -1) { perror("getumask"); exit(1); } printf("umask = %o\n", r); exit(0); } $ ./getumask umask = 22 Rich.