Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760438AbcDMLn0 (ORCPT ); Wed, 13 Apr 2016 07:43:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57911 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759227AbcDMLnU (ORCPT ); Wed, 13 Apr 2016 07:43:20 -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 Subject: [PATCH 0/2] vfs: Define new syscall getumask. Date: Wed, 13 Apr 2016 12:43:04 +0100 Message-Id: <1460547786-16766-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: 1065 Lines: 41 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.