diff options
author | Ondrej Oprala <ooprala@redhat.com> | 2012-08-09 17:34:09 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2012-08-21 19:49:36 +0200 |
commit | cf7e1b5b8fb53aef2a9103a32d6ad5ee0b595fa6 (patch) | |
tree | 3ca0676bc50e49c2efea20fb96614fb978a911be /tests/du | |
parent | fe5b5eed94213745e04fa63e212896ed1055d83e (diff) | |
download | coreutils-cf7e1b5b8fb53aef2a9103a32d6ad5ee0b595fa6.tar.xz |
du: handle bind-mounted directory cycles gracefully
Before this change, a directory cycle induced by a bind mount
would be treated as a fatal error, i.e., probable disk corruption.
However, such cycles are relatively common, and can be detected
efficiently, so now du emits a descriptive warning and arranges
to exit nonzero.
* NEWS (Bug fixes): Mention it.
* src/du.c: Include "mountlist.h".
(di_mnt): New global set.
(di_files): Rename global from di_set, now that there are two.
(fill_mount_table): New function.
(hash_ins): Add DI_SET parameter.
(process_file): Look up each dir dev/ino pair in the new set.
(main): Allocate, initialize, and free the new set.
* tests/du/bind-mount-dir-cycle: Add a test for the fix.
* tests/Makefile.am (TESTS): Add it.
* THANKS.in: Update.
This implements the proposal in http://bugs.gnu.org/11844.
Originally reported in http://bugs.debian.org/563254 by Alan Jenkins
and more recently as http://bugzilla.redhat.com/836557
Improved by: Jim Meyering
Diffstat (limited to 'tests/du')
-rwxr-xr-x | tests/du/bind-mount-dir-cycle | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/du/bind-mount-dir-cycle b/tests/du/bind-mount-dir-cycle new file mode 100755 index 000000000..8f9e197f9 --- /dev/null +++ b/tests/du/bind-mount-dir-cycle @@ -0,0 +1,44 @@ +#!/bin/sh +# Exercise du's new ability to handle bind-mount-induced dir cycles. + +# Copyright (C) 2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +require_root_ + +cleanup_() +{ + # When you take the undesirable shortcut of making /etc/mtab a link + # to /proc/mounts, unmounting "$other_partition_tmpdir" would fail. + # So, here we unmount a/b instead. + umount a/b +} + +mkdir -p a/b || framework_failure_ +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 +sed 's/^[0-9][0-9]* //' out > k && mv k out + +compare exp-err err || fail=1 +compare exp out || fail=1 + +Exit $fail |