* why we need openat et al in the kernel
@ 2005-11-12 14:12 Jim Meyering
0 siblings, 0 replies; only message in thread
From: Jim Meyering @ 2005-11-12 14:12 UTC (permalink / raw)
To: linux-kernel; +Cc: bug-gnulib
[ I have to preface this by saying I'm not interested in the
attribute-related semantics of openat, but rather in the
fd-relative-open--related semantics. ]
Why do we need openat and related functions in the kernel?
Without openat-like functions[1], it is impossible to process
an arbitrarily deep hierarchy (efficiently) or even a single
arbitrarily-distant file without changing the working directory.
Even on systems with no PATH_MAX limitation, it is prohibitively
expensive (O(depth**2)) to process a deep hierarchy without
changing the working directory or using openat-like functions.
What's wrong with changing the working directory?
- it makes the code non-reentrant. Imagine a function that processes
a directory hierarchy. In order to deal with an arbitrarily deep
hierarchy, it uses open and fchdir as it traverses the tree. If
this function is called in a multi-threaded application, other
threads may find the current working directory changed out from
under them.
- it may make it impossible to return to the original working directory.
For example, consider the command `rm -r /tmp/deep dot-relative'.
Removing /tmp/deep may require changing into /tmp/deep then
/tmp/deep/sub, then /tmp/deep/sub/2, ... If the initial working
directory was not readable (so couldn't be opened) and getcwd fails,
then there is no way to return and remove. Yes, this is contrived :-)
Note that glibc (as of Nov 11, 2005) provides openat et. al., but that
its implementation relies on the /proc file system, which isn't always
usable, even on systems with the required kernel options: e.g., in a
restrictive chroot environment.
Why does openat have to be implemented in the kernel?
Because any emulation cannot be 100% effective. Gnulib's
save_cwd fails if the working directory is not readable
and too deep for getcwd. restore_cwd can fail if save_cwd
failed to get a file descriptor and the original directory
is gone or inaccessible.
So, is there any interest in adding these functions,
independent of the attribute-related debate?
Jim
[1] The list of functions Solaris provides: openat, fchownat, fstatat,
futimesat, renameat, unlinkat. Plus, a library-level function: fdopendir.
In rewriting GNU rm (coreutils/src/remove.c) to use these functions,
I've identified one more that is required: euidaccessat.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-11-12 14:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-12 14:12 why we need openat et al in the kernel Jim Meyering
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®