]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
du: ignore directory cycles due to bind mounts
authorPádraig Brady <P@draigBrady.com>
Thu, 19 Jun 2014 11:11:00 +0000 (12:11 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 24 Jun 2014 13:39:34 +0000 (14:39 +0100)
* src/du.c (process_file): Treat cycles due to bind mounts
like cycles due to following symlinks.
* tests/du/bind-mount-dir-cycle.sh: Adjust accordingly.
* NEWS: Mention the change in behavior.
Reported at http://bugzilla.redhat.com/836557

NEWS
src/du.c
tests/du/bind-mount-dir-cycle.sh

diff --git a/NEWS b/NEWS
index 77286f884e244abb5fb5e2a8f1fb326ebd92d91f..d3c23680c63ffcc9390a2fa0b2ae8c106d4bec9d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -48,6 +48,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   display the correct device name for directories mounted multiple times.
   [These bugs were present in "the beginning".]
 
+  du now silently ignores directory cycles introduced with bind mounts.
+  Previously it would issue a warning and exit with a failure status.
+
   head --bytes=-N and --lines=-N now handles devices more
   consistently, not ignoring data from virtual devices like /dev/zero,
   or on BSD systems data from tty devices.
index e4509fd7802e495ffaca20ec2a129c847f865d65..0966326b5a8afc23ed09e17043cfd6076eb39df9 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -514,15 +514,11 @@ process_file (FTS *fts, FTSENT *ent)
           break;
 
         case FTS_DC:
-          if (cycle_warning_required (fts, ent))
+          /* If not following symlinks and not a (bind) mount point.  */
+          if (cycle_warning_required (fts, ent)
+              && ! di_set_lookup (di_mnt, sb->st_dev, sb->st_ino))
             {
-              /* If this is a mount point, then diagnose it and avoid
-                 the cycle.  */
-              if (di_set_lookup (di_mnt, sb->st_dev, sb->st_ino))
-                error (0, 0, _("mount point %s already traversed"),
-                       quote (file));
-              else
-                emit_cycle_warning (file);
+              emit_cycle_warning (file);
               return false;
             }
           return true;
index 4fef345cd80c2ebf7cd3ca2f81e9034c14ed5eac..ac6bf2e2471f0cb9c65a26fcb5d09f7ec3bb0c26 100755 (executable)
@@ -27,12 +27,11 @@ mount --bind a a/b \
   || skip_ "This test requires mount with a working --bind option."
 
 echo a > exp || framework_failure_
-echo "du: mount point 'a/b' already traversed" > exp-err || framework_failure_
 
-du a > out 2> err && fail=1
+du a > out 2> err || fail=1
 sed 's/^[0-9][0-9]*    //' out > k && mv k out
 
-compare exp-err err || fail=1
+compare /dev/null err || fail=1
 compare exp out || fail=1
 
 Exit $fail