Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753827AbcDNKWF (ORCPT ); Thu, 14 Apr 2016 06:22:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37275 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751994AbcDNKWD (ORCPT ); Thu, 14 Apr 2016 06:22:03 -0400 Subject: Re: [PATCH] procfs: expose umask in /proc//status To: "Richard W.M. Jones" , corbet@lwn.net References: <1460626489-31932-1-git-send-email-rjones@redhat.com> <1460626489-31932-2-git-send-email-rjones@redhat.com> Cc: akpm@linux-foundation.org, vbabka@suse.cz, mhocko@suse.com, hughd@google.com, koct9i@gmail.com, chenhanxiao@cn.fujitsu.com, n-horiguchi@ah.jp.nec.com, ross.zwisler@linux.intel.com, john.stultz@linaro.org, minchan@kernel.org, hannes@cmpxchg.org, nathans@redhat.com, andriy.shevchenko@linux.intel.com, keescook@chromium.org, gorcunov@openvz.org, joe@perches.com, linux@rasmusvillemoes.dk, mingo@kernel.org, cmetcalf@ezchip.com, iago@endocode.com, luto@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, gorcunov@gmail.com, fw@deneb.enyo.de, walters@verbum.org From: Jerome Marchand Message-ID: <570F6F37.50209@redhat.com> Date: Thu, 14 Apr 2016 12:21:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <1460626489-31932-2-git-send-email-rjones@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="310pWvjImrb3JDrNvlDHdCnJdXnAIxv7r" X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 14 Apr 2016 10:22:01 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5278 Lines: 149 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --310pWvjImrb3JDrNvlDHdCnJdXnAIxv7r Content-Type: multipart/mixed; boundary="34hPMHfh5HRv6LvDeGCBomunkgPse3r9S" From: Jerome Marchand To: "Richard W.M. Jones" , corbet@lwn.net Cc: akpm@linux-foundation.org, vbabka@suse.cz, mhocko@suse.com, hughd@google.com, koct9i@gmail.com, chenhanxiao@cn.fujitsu.com, n-horiguchi@ah.jp.nec.com, ross.zwisler@linux.intel.com, john.stultz@linaro.org, minchan@kernel.org, hannes@cmpxchg.org, nathans@redhat.com, andriy.shevchenko@linux.intel.com, keescook@chromium.org, gorcunov@openvz.org, joe@perches.com, linux@rasmusvillemoes.dk, mingo@kernel.org, cmetcalf@ezchip.com, iago@endocode.com, luto@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, gorcunov@gmail.com, fw@deneb.enyo.de, walters@verbum.org Message-ID: <570F6F37.50209@redhat.com> Subject: Re: [PATCH] procfs: expose umask in /proc//status References: <1460626489-31932-1-git-send-email-rjones@redhat.com> <1460626489-31932-2-git-send-email-rjones@redhat.com> In-Reply-To: <1460626489-31932-2-git-send-email-rjones@redhat.com> --34hPMHfh5HRv6LvDeGCBomunkgPse3r9S Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 04/14/2016 11:34 AM, Richard W.M. Jones wrote: > 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. >=20 > Add a new status line ("Umask") in /proc//status. It contains > the file mode creation mask (umask) in octal. It is only shown for > tasks which have task->fs. >=20 > This patch is adapted from one originally written by Pierre Carrier. >=20 > Signed-off-by: Richard W.M. Jones > --- > Documentation/filesystems/proc.txt | 1 + > fs/proc/array.c | 20 +++++++++++++++++++- > 2 files changed, 20 insertions(+), 1 deletion(-) >=20 > diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesys= tems/proc.txt > index 7f5607a..e8d0075 100644 > --- a/Documentation/filesystems/proc.txt > +++ b/Documentation/filesystems/proc.txt > @@ -225,6 +225,7 @@ Table 1-2: Contents of the status files (as of 4.1)= > TracerPid PID of process tracing this process (0 if= not) > Uid Real, effective, saved set, and file sys= tem UIDs > Gid Real, effective, saved set, and file sys= tem GIDs > + Umask file mode creation mask > FDSize number of file descriptor slots currently= allocated > Groups supplementary group list > NStgid descendant namespace thread group ID hier= archy > diff --git a/fs/proc/array.c b/fs/proc/array.c > index b6c00ce..03e8d3f 100644 > --- a/fs/proc/array.c > +++ b/fs/proc/array.c > @@ -83,6 +83,7 @@ > #include > #include > #include > +#include > =20 > #include > #include > @@ -139,12 +140,25 @@ static inline const char *get_task_state(struct t= ask_struct *tsk) > return task_state_array[fls(state)]; > } > =20 > +static inline int get_task_umask(struct task_struct *tsk) > +{ > + struct fs_struct *fs; > + int umask =3D -ENOENT; > + > + task_lock(tsk); > + fs =3D tsk->fs; > + if (fs) > + umask =3D fs->umask; > + task_unlock(tsk); > + return umask; > +} > + > static inline void task_state(struct seq_file *m, struct pid_namespace= *ns, > struct pid *pid, struct task_struct *p) > { > struct user_namespace *user_ns =3D seq_user_ns(m); > struct group_info *group_info; > - int g; > + int g, umask; > struct task_struct *tracer; > const struct cred *cred; > pid_t ppid, tpid =3D 0, tgid, ngid; > @@ -162,6 +176,10 @@ static inline void task_state(struct seq_file *m, = struct pid_namespace *ns, > ngid =3D task_numa_group_id(p); > cred =3D get_task_cred(p); > =20 > + umask =3D get_task_umask(p); > + if (umask >=3D 0) > + seq_printf(m, "Umask:\t0%o\n", umask); It seems to me that umasks are usually displayed in the form 0XXX, such as the output of umask command. So what about: seq_printf(m, "Umask:\t%#04o\n", umask); Provided printk() supports those flags, of course. Thanks, Jerome > + > task_lock(p); > if (p->files) > max_fds =3D files_fdtable(p->files)->max_fds; >=20 --34hPMHfh5HRv6LvDeGCBomunkgPse3r9S-- --310pWvjImrb3JDrNvlDHdCnJdXnAIxv7r Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJXD283AAoJEHTzHJCtsuoCVTQIALUpJUlzF3deot9EIxAab7aX e5d2ypOOA4ymFOUIeG+72WWGNHT277zTFoFSwSGdZQUPOE+eNVm9iVD3+Oerp98A fHYCw9ZGhdaZsWTxb9w3ReoOoRP22ZQcXY9VAULTr94TNfsBbIY34XYNDDkn9M31 1pEdR3Cs46O6PgRq4rrMnhi+/eSNMgas8yYSeUe1Ug+SWaOh8et7K4hp0Zwt65Bh frCy/zMXW8QhV8DHHS3rL8RC1xor6hueO99BK6dUEHf+/3DOLuTUD4NARd+ru+8C jOFIxHCSSUEd/bAFM1/93vg+n/EiNiFfO876bxR75F/QEeKKn2qpENKBELhxEWA= =8/gb -----END PGP SIGNATURE----- --310pWvjImrb3JDrNvlDHdCnJdXnAIxv7r--