summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-12-26 18:53:58 +0000
committerJim Meyering <jim@meyering.net>2005-12-26 18:53:58 +0000
commitedf69af3173e70c4a0ce743a74d2313f37ebbbe8 (patch)
treeff612249ec758a69b1d0111d234cd1516273b7b1
parent078800a00bb003fd077283366f90a8b9ffd8e22e (diff)
downloadcoreutils-edf69af3173e70c4a0ce743a74d2313f37ebbbe8.tar.xz
(chdir_no_follow): Move declaration of local,
sb2, `down' into the scope where it is used. Note that on some systems this function also fails when DIR is a writable-yet-unreadable directory.
-rw-r--r--lib/chdir-safer.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/chdir-safer.c b/lib/chdir-safer.c
index 539eb2d68..f6b42ce9d 100644
--- a/lib/chdir-safer.c
+++ b/lib/chdir-safer.c
@@ -45,9 +45,12 @@
/* Like chdir, but fail if DIR is a symbolic link to a directory (or
similar funny business), or if DIR is neither readable nor
- writeable. This avoids a minor race condition between when a
- directory is created or statted and when the process chdirs into
- it. */
+ writable. This avoids a minor race condition between when a
+ directory is created or statted and when the process chdirs into it.
+
+ On some systems, a writable yet unreadable directory cannot be
+ opened via open with O_WRONLY. For example, on Linux 2.6, the
+ open syscall fails with EISDIR. */
int
chdir_no_follow (char const *dir)
{
@@ -70,11 +73,10 @@ chdir_no_follow (char const *dir)
if (! O_NOFOLLOW)
{
struct stat sb1;
- struct stat sb2;
-
result = lstat (dir, &sb1);
if (result == 0)
{
+ struct stat sb2;
result = fstat (fd, &sb2);
if (result == 0 && ! SAME_INODE (sb1, sb2))
{