bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug in ftw.c [Re: address@hidden: Bug#180228: du dirA dirB broken]


From: Jim Meyering
Subject: bug in ftw.c [Re: address@hidden: Bug#180228: du dirA dirB broken]
Date: Sat, 08 Feb 2003 18:39:02 +0100

[ To those of you who are new to this thread, there's a bug that
  provokes a failure in du from coreutils-4.5.6.  Details here.
    http://bugs.debian.org/180228  ]

Argh!
Thanks to both of you!

That sure looks like it's due to a bug in n/ftw with FTW_CHDIR.
It's supposed to restore the working directory before returning.
When invoked with a directory name containing no slashes, it doesn't do that.


Here's a patch.

2003-02-08  Jim Meyering  <address@hidden>

        * ftw.c (ftw_startup): When using FTW_CHDIR, always remember
        the current directory, not just when DIR contains a slash.
        Reported by Manoj Srivastava via Michael Stone as Debian bug #180228.

Index: ftw.c
===================================================================
RCS file: /fetish/cu/lib/ftw.c,v
retrieving revision 1.16
diff -u -p -u -p -r1.16 ftw.c
--- ftw.c       7 Feb 2003 09:28:50 -0000       1.16
+++ ftw.c       8 Feb 2003 17:00:50 -0000
@@ -691,13 +691,13 @@ ftw_startup (const char *dir, int is_nft
   data.known_objects = NULL;
 
   /* Now go to the directory containing the initial file/directory.  */
-  if ((flags & FTW_CHDIR) && data.ftw.base > 0)
+  if (flags & FTW_CHDIR)
     {
       /* GNU extension ahead.  */
       cwd =  __getcwd (NULL, 0);
       if (cwd == NULL)
        result = -1;
-      else
+      else if (data.ftw.base > 0)
        {
          /* Change to the directory the file is in.  In data.dirbuf
             we have a writable copy of the file name.  Just NUL


Ulrich,

In case you'd like a test case, here's one

  $ mkdir -p z/z
  $ ./x z
  wd before: /u/my/work/fetish/cu/src/du-junk/glibc-ftw-bug/slink-..-test
  wd after:  /u/my/work/fetish/cu/src/du-junk/glibc-ftw-bug/slink-..-test/z

Using this code (compiled with the ftw.c, xgetcwd.c, and xmalloc.c
and config.h from coreutils-4.5.6):  Note that it uses the new `skip'
member that I've had to add in the version of ftw.c used by coreutils.
For your test, you can remove that line.
---------------------------------------
#include "config.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <ftw.h>

static int
cb (const char *file, const struct stat64 *sb, int file_type, struct FTW *info)
{
  info->skip = 0;
  return 0;
}

int
main (int argc, char **argv)
{
  int flags = FTW_PHYS | FTW_MOUNT | FTW_CHDIR | FTW_DEPTH;
  int err = 0, i;
  if (argc < 2)
    exit (2);
  for (i = 1; i < argc; i++)
    {
      printf ("wd before: %s\n", getcwd (NULL, 0));
      err |= nftw64 (argv[i], cb, 30, flags);
      printf ("wd after:  %s\n", getcwd (NULL, 0));
    }
  exit (err);
}
---------------------------------------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]