summaryrefslogtreecommitdiff
path: root/lib/openat.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2006-01-17 17:43:10 +0000
committerJim Meyering <jim@meyering.net>2006-01-17 17:43:10 +0000
commitd55e2d85284674dc6a0f623759aef0174d802f9e (patch)
tree8ea2dc168fca59a77d0cbd54b5af10c2a2e7f17f /lib/openat.c
parent88df081621f9517ed9777c0b954915d747025353 (diff)
downloadcoreutils-d55e2d85284674dc6a0f623759aef0174d802f9e.tar.xz
(openat_needs_fchdir): New function.
Diffstat (limited to 'lib/openat.c')
-rw-r--r--lib/openat.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/openat.c b/lib/openat.c
index 273c5b6ec..764d475ff 100644
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -35,7 +35,8 @@
/* Replacement for Solaris' openat function.
<http://www.google.com/search?q=openat+site:docs.sun.com>
- Simulate it by doing save_cwd/fchdir/open/restore_cwd.
+ First, try to simulate it via open ("/proc/self/fd/FD/FILE").
+ Failing that, simulate it by doing save_cwd/fchdir/open/restore_cwd.
If either the save_cwd or the restore_cwd fails (relatively unlikely,
and usually indicative of a problem that deserves close attention),
then give a diagnostic and exit nonzero.
@@ -127,11 +128,32 @@ openat_permissive (int fd, char const *file, int flags, mode_t mode,
return err;
}
+/* Return true if our openat implementation must resort to
+ using save_cwd and restore_cwd. */
+bool
+openat_needs_fchdir (void)
+{
+ int fd2;
+ int fd = open ("/", O_RDONLY);
+ char *proc_file;
+
+ if (fd < 0)
+ return true;
+ BUILD_PROC_NAME (proc_file, fd, ".");
+ fd2 = open (proc_file, O_RDONLY);
+ close (fd);
+ if (0 <= fd2)
+ close (fd2);
+
+ return fd2 < 0;
+}
+
#if !HAVE_FDOPENDIR
/* Replacement for Solaris' function by the same name.
<http://www.google.com/search?q=fdopendir+site:docs.sun.com>
- Simulate it by doing save_cwd/fchdir/opendir(".")/restore_cwd.
+ First, try to simulate it via opendir ("/proc/self/fd/FD"). Failing
+ that, simulate it by doing save_cwd/fchdir/opendir(".")/restore_cwd.
If either the save_cwd or the restore_cwd fails (relatively unlikely,
and usually indicative of a problem that deserves close attention),
then give a diagnostic and exit nonzero.
@@ -187,7 +209,8 @@ fdopendir (int fd)
/* Replacement for Solaris' function by the same name.
<http://www.google.com/search?q=fstatat+site:docs.sun.com>
- Simulate it by doing save_cwd/fchdir/(stat|lstat)/restore_cwd.
+ First, try to simulate it via l?stat ("/proc/self/fd/FD/FILE").
+ Failing that, simulate it via save_cwd/fchdir/(stat|lstat)/restore_cwd.
If either the save_cwd or the restore_cwd fails (relatively unlikely,
and usually indicative of a problem that deserves close attention),
then give a diagnostic and exit nonzero.
@@ -241,7 +264,8 @@ fstatat (int fd, char const *file, struct stat *st, int flag)
/* Replacement for Solaris' function by the same name.
<http://www.google.com/search?q=unlinkat+site:docs.sun.com>
- Simulate it by doing save_cwd/fchdir/(unlink|rmdir)/restore_cwd.
+ First, try to simulate it via (unlink|rmdir) ("/proc/self/fd/FD/FILE").
+ Failing that, simulate it via save_cwd/fchdir/(unlink|rmdir)/restore_cwd.
If either the save_cwd or the restore_cwd fails (relatively unlikely,
and usually indicative of a problem that deserves close attention),
then give a diagnostic and exit nonzero.