summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rw-r--r--src/df.c3
-rwxr-xr-xtests/df/skip-duplicates.sh32
3 files changed, 25 insertions, 14 deletions
diff --git a/NEWS b/NEWS
index 75ec253ee..53c9f4aef 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@ GNU coreutils NEWS -*- outline -*-
** Bug fixes
+ df now processes the mount list correctly in the presence of unstatable
+ mount points. Previously it may have failed to output some mount points.
+ [bug introduced in coreutils-8.21]
+
install now removes the target file if the strip program failed for any
reason. Before, that file was left behind, sometimes even with wrong
permissions.
diff --git a/src/df.c b/src/df.c
index 051513196..bc507c72e 100644
--- a/src/df.c
+++ b/src/df.c
@@ -620,7 +620,8 @@ filter_mount_list (void)
if (-1 == stat (me->me_mountdir, &buf))
{
- ; /* Stat failed - add ME to be able to complain about it later. */
+ /* Stat failed - add ME to be able to complain about it later. */
+ buf.st_dev = me->me_dev;
}
else
{
diff --git a/tests/df/skip-duplicates.sh b/tests/df/skip-duplicates.sh
index 2b7de562b..1e94dc0b2 100755
--- a/tests/df/skip-duplicates.sh
+++ b/tests/df/skip-duplicates.sh
@@ -24,8 +24,10 @@ require_gcc_shared_
df || skip_ "df fails"
# Simulate an mtab file with two entries of the same device number.
+# Also add entries with unstatable mount dirs to ensure that's handled.
cat > k.c <<'EOF' || framework_failure_
#include <stdio.h>
+#include <stdlib.h>
#include <mntent.h>
struct mntent *getmntent (FILE *fp)
@@ -38,20 +40,20 @@ struct mntent *getmntent (FILE *fp)
++done;
}
- static struct mntent mntent;
+ static struct mntent mntents[] = {
+ {.mnt_fsname="/short", .mnt_dir="/invalid/mount/dir"},
+ {.mnt_fsname="fsname", .mnt_dir="/",},
+ {.mnt_fsname="/fsname", .mnt_dir="/root"},
+ {.mnt_fsname="/fsname", .mnt_dir="/"},
+ };
- while (done++ < 4)
+ if (!getenv ("CU_TEST_DUPE_INVALID") && done == 1)
+ done++; /* skip the first entry. */
+
+ while (done++ <= 4)
{
- /* File system - Mounted on
- fsname /
- /fsname /root
- /fsname /
- */
- mntent.mnt_fsname = (done == 2) ? "fsname" : "/fsname";
- mntent.mnt_dir = (done == 3) ? "/root" : "/";
- mntent.mnt_type = "-";
-
- return &mntent;
+ mntents[done-2].mnt_type = "-";
+ return &mntents[done-2];
}
return NULL;
}
@@ -65,12 +67,16 @@ gcc --std=gnu99 -shared -fPIC -ldl -O2 k.c -o k.so \
LD_PRELOAD=./k.so df
test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?"
-# The fake mtab file should only contain 2 entries, both
+# The fake mtab file should only contain entries
# having the same device number; thus the output should
# consist of a header and one entry.
LD_PRELOAD=./k.so df >out || fail=1
test $(wc -l <out) -eq 2 || { fail=1; cat out; }
+# Ensure we fail when unable to stat invalid entries
+LD_PRELOAD=./k.so CU_TEST_DUPE_INVALID=1 df >out && fail=1
+test $(wc -l <out) -eq 2 || { fail=1; cat out; }
+
# df should also prefer "/fsname" over "fsname"
test $(grep -c '/fsname' <out) -eq 1 || { fail=1; cat out; }
# ... and "/fsname" with '/' as Mounted on over '/root'