du: handle bind-mounted directory cycles gracefully
authorOndrej Oprala <ooprala@redhat.com>
Thu, 9 Aug 2012 15:34:09 +0000 (17:34 +0200)
committerJim Meyering <meyering@redhat.com>
Tue, 21 Aug 2012 17:49:36 +0000 (19:49 +0200)
commitcf7e1b5b8fb53aef2a9103a32d6ad5ee0b595fa6
tree3ca0676bc50e49c2efea20fb96614fb978a911be
parentfe5b5eed94213745e04fa63e212896ed1055d83e
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
NEWS
THANKS.in
src/du.c
tests/Makefile.am
tests/du/bind-mount-dir-cycle [new file with mode: 0755]