[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160413160320.GI11600@redhat.com>
Date: Wed, 13 Apr 2016 17:03:20 +0100
From: "Richard W.M. Jones" <rjones@...hat.com>
To: Colin Walters <walters@...bum.org>
Cc: linux-kernel@...r.kernel.org, tglx@...utronix.de, mingo@...hat.com,
hpa@...or.com, akpm@...ux-foundation.org, luto@...nel.org,
viro@...iv.linux.org.uk, mathieu.desnoyers@...icios.com,
zab@...hat.com, emunson@...mai.com, paulmck@...ux.vnet.ibm.com,
aarcange@...hat.com, josh@...htriplett.org, xemul@...allels.com,
sfr@...b.auug.org.au, milosz@...in.com, rostedt@...dmis.org,
arnd@...db.de, ebiederm@...ssion.com, gorcunov@...nvz.org,
iulia.manda21@...il.com, dave.hansen@...ux.intel.com,
mguzik@...hat.com, adobriyan@...il.com, dave@...olabs.net,
linux-api@...r.kernel.org, gorcunov@...il.com, fw@...eb.enyo.de
Subject: Re: [PATCH v2 0/2] vfs: Define new syscall getumask.
On Wed, Apr 13, 2016 at 11:41:45AM -0400, Colin Walters wrote:
> On Wed, Apr 13, 2016, at 08:57 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.
>
> I assume you just want to do this from a shared library so you can
> determine whether or not you need to call fchown() after making files
> and the like? If that's the case it'd be good to note it in the commit
> message.
Yes, the use case is something like that. I write a shared library
(libguestfs) and we get bug reports that turn out to be caused by odd
umask settings. Of course we fix these on a case-by-case basis, but
we also want to include the current umask in debug output so that we
can identify the problem quickly in future reports.
Actually I wrote a rather involved getumask substitute:
https://github.com/libguestfs/libguestfs/blob/master/src/launch.c#L477
It works by creating a temporary directory, writing a file inside that
directory with mode 0777, then calling fstat(2) to work out what mode
the kernel gave it.
It turns out this code is not even correct. It was pointed out to me
that there is a filesystem umask mount option (and fmask, dmask too)
which stops this from working properly.
So it's a lot of work to read umask safely inside a shared library.
I will update the commit comment with a brief summary of the above.
> BTW...it might be a good idea to add a flags argument:
> https://lwn.net/Articles/585415/
>
> Did you consider calling this `umask2`, having the initial version
> only support retrieving it via a UMASK_GET flag, and lay the
> groundwork to support setting a threadsafe umask with a
> UMASK_SET_THREAD flag?
Can certainly do it like this if that is preferable.
For my needs, getumask as implemented now is sufficient.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
Powered by blists - more mailing lists