[coreutils/f17] fix showing duplicates in df (#709351, O.Oprala, B.Voelker)
Ondrej Vasik
ovasik at fedoraproject.org
Wed Dec 12 11:17:08 UTC 2012
commit d1f444bc8f31954b84194e1c41e85589f1b58770
Author: Ondřej Vašík <ovasik at redhat.com>
Date: Wed Dec 12 12:17:01 2012 +0100
fix showing duplicates in df (#709351, O.Oprala, B.Voelker)
coreutils-8.17-df-duplicates.patch | 264 ++++++++++++++++++++++++++++++++++++
coreutils.spec | 7 +-
2 files changed, 270 insertions(+), 1 deletions(-)
---
diff --git a/coreutils-8.17-df-duplicates.patch b/coreutils-8.17-df-duplicates.patch
new file mode 100644
index 0000000..06983ad
--- /dev/null
+++ b/coreutils-8.17-df-duplicates.patch
@@ -0,0 +1,264 @@
+diff -urNp coreutils-8.17-orig/doc/coreutils.texi coreutils-8.17/doc/coreutils.texi
+--- coreutils-8.17-orig/doc/coreutils.texi 2012-05-10 09:14:30.000000000 +0200
++++ coreutils-8.17/doc/coreutils.texi 2012-12-11 11:30:38.730760947 +0100
+@@ -10561,6 +10561,14 @@ Normally the disk space is printed in un
+ 1024 bytes, but this can be overridden (@pxref{Block size}).
+ Non-integer quantities are rounded up to the next higher unit.
+
++For bind mounts and without arguments, @command{df} only outputs the statistics
++for the first occurence of that device in the list of file systems (@var{mtab}),
++i.e., it hides duplicate entries, unless the @option{-a} option is specified.
++
++By default, @command{df} omits the early-boot pseudo file system type
++ at samp{rootfs}, unless the @option{-a} option is specified or that file system
++type is explicitly to be included by using the @option{-t} option.
++
+ @cindex disk device file
+ @cindex device file, disk
+ If an argument @var{file} is a disk device file containing a mounted
+diff -urNp coreutils-8.17-orig/src/df.c coreutils-8.17/src/df.c
+--- coreutils-8.17-orig/src/df.c 2012-05-01 22:55:08.000000000 +0200
++++ coreutils-8.17/src/df.c 2012-12-11 11:30:38.803069545 +0100
+@@ -46,6 +46,17 @@
+ /* If true, show inode information. */
+ static bool inode_format;
+
++/* Filled with device numbers of examined file systems to avoid
++ duplicities in output. */
++struct devlist
++{
++ dev_t dev_num;
++ struct devlist *next;
++};
++
++/* Store of already-processed device numbers. */
++static struct devlist *devlist_head;
++
+ /* If true, show even file systems with zero size or
+ uninteresting types. */
+ static bool show_all_fs;
+@@ -57,6 +68,12 @@ static bool show_local_fs;
+ command line argument -- even if it's a dummy (automounter) entry. */
+ static bool show_listed_fs;
+
++/* If true, include rootfs in the output. */
++static bool show_rootfs;
++
++/* The literal name of the initial root file system. */
++static char const *ROOTFS = "rootfs";
++
+ /* Human-readable options for output. */
+ static int human_output_opts;
+
+@@ -350,6 +367,29 @@ excluded_fstype (const char *fstype)
+ return false;
+ }
+
++/* Check if the device was already examined. */
++
++static bool
++dev_examined (char const *mount_dir, char const *devname)
++{
++ struct stat buf;
++ if (-1 == stat (mount_dir, &buf))
++ return false;
++
++ struct devlist *devlist = devlist_head;
++ for ( ; devlist; devlist = devlist->next)
++ if (devlist->dev_num == buf.st_dev)
++ return true;
++
++ /* Add the device number to the global list devlist. */
++ devlist = xmalloc (sizeof *devlist);
++ devlist->dev_num = buf.st_dev;
++ devlist->next = devlist_head;
++ devlist_head = devlist;
++
++ return false;
++}
++
+ /* Return true if N is a known integer value. On many file systems,
+ UINTMAX_MAX represents an unknown value; on AIX, UINTMAX_MAX - 1
+ represents unknown. Use a rule that works on AIX file systems, and
+@@ -474,6 +514,15 @@ get_dev (char const *disk, char const *m
+ if (!selected_fstype (fstype) || excluded_fstype (fstype))
+ return;
+
++ if (process_all && !show_all_fs && !show_listed_fs)
++ {
++ /* No arguments nor "df -a", then check if df has to ... */
++ if (!show_rootfs && STREQ (disk, ROOTFS))
++ return; /* ... skip rootfs: (unless -trootfs is given. */
++ if (dev_examined (mount_point, disk))
++ return; /* ... skip duplicate entries (bind mounts). */
++ }
++
+ /* If MOUNT_POINT is NULL, then the file system is not mounted, and this
+ program reports on the file system that the special file is on.
+ It would be better to report on the unmounted file system,
+@@ -972,6 +1021,7 @@ main (int argc, char **argv)
+ /* Accept -F as a synonym for -t for compatibility with Solaris. */
+ case 't':
+ add_fs_type (optarg);
++ show_rootfs = selected_fstype (ROOTFS);
+ break;
+
+ case 'v': /* For SysV compatibility. */
+@@ -1105,6 +1155,14 @@ main (int argc, char **argv)
+
+ if (! file_systems_processed)
+ error (EXIT_FAILURE, 0, _("no file systems processed"));
++ IF_LINT (
++ while (devlist_head)
++ {
++ struct devlist *devlist = devlist_head->next;
++ free (devlist_head);
++ devlist_head = devlist;
++ }
++ );
+
+ exit (exit_status);
+ }
+diff -urNp coreutils-8.17-orig/tests/df/skip-duplicates coreutils-8.17/tests/df/skip-duplicates
+--- coreutils-8.17-orig/tests/df/skip-duplicates 1970-01-01 01:00:00.000000000 +0100
++++ coreutils-8.17/tests/df/skip-duplicates 2012-12-11 11:30:38.820762450 +0100
+@@ -0,0 +1,77 @@
++#!/bin/sh
++# Test df's behavior when the mount list contains duplicate entries.
++# This test is skipped on systems that lack LD_PRELOAD support; that's fine.
++
++# 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_ df
++
++df || skip_ "df fails"
++
++# Simulate an mtab file with two entries of the same device number.
++cat > k.c <<'EOF' || framework_failure_
++#include <stdio.h>
++#include <mntent.h>
++
++struct mntent *getmntent (FILE *fp)
++{
++ /* Prove that LD_PRELOAD works. */
++ static int done = 0;
++ if (!done)
++ {
++ fclose (fopen ("x", "w"));
++ ++done;
++ }
++
++ static struct mntent mntent;
++
++ while (done++ < 3)
++ {
++ mntent.mnt_fsname = "fsname";
++ mntent.mnt_dir = "/";
++ mntent.mnt_type = "-";
++
++ return &mntent;
++ }
++ return NULL;
++}
++EOF
++
++# Then compile/link it:
++gcc --std=gnu99 -shared -fPIC -ldl -O2 k.c -o k.so \
++ || skip_ "getmntent hack does not work on this platform"
++
++# Test if LD_PRELOAD works:
++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
++# 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 that filtering duplicates does not affect -a processing.
++LD_PRELOAD=./k.so df -a >out || fail=1
++test $(wc -l <out) -eq 3 || { fail=1; cat out; }
++
++# Ensure that filtering duplcates does not affect
++# argument processing (now without the fake getmntent()).
++df '.' '.' >out || fail=1
++test $(wc -l <out) -eq 3 || { fail=1; cat out; }
++
++Exit $fail
+diff -urNp coreutils-8.17-orig/tests/df/skip-rootfs coreutils-8.17/tests/df/skip-rootfs
+--- coreutils-8.17-orig/tests/df/skip-rootfs 1970-01-01 01:00:00.000000000 +0100
++++ coreutils-8.17/tests/df/skip-rootfs 2012-12-11 11:30:38.821762595 +0100
+@@ -0,0 +1,46 @@
++#!/bin/sh
++# Test df's behavior for skipping the pseudo "rootfs" file system.
++
++# 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_ df
++
++df || skip_ "df fails"
++
++# Verify that rootfs is in mtab (and shown when the -a option is specified).
++df -a >out || fail=1
++grep '^rootfs' out || skip_ "no rootfs in mtab"
++
++# Ensure that rootfs is supressed when no options is specified.
++df >out || fail=1
++grep '^rootfs' out && { fail=1; cat out; }
++
++# Ensure that the rootfs is shown when explicitly specifying "-t rootfs".
++df -t rootfs >out || fail=1
++grep '^rootfs' out || { fail=1; cat out; }
++
++# Ensure that the rootfs is shown when explicitly specifying "-t rootfs",
++# even when the -a option is specified.
++df -t rootfs -a >out || fail=1
++grep '^rootfs' out || { fail=1; cat out; }
++
++# Ensure that the rootfs is omitted in all_fs mode when it is explicitly
++# black-listed.
++df -a -x rootfs >out || fail=1
++grep '^rootfs' out && { fail=1; cat out; }
++
++Exit $fail
+diff -urNp coreutils-8.17-orig/tests/Makefile.am coreutils-8.17/tests/Makefile.am
+--- coreutils-8.17-orig/tests/Makefile.am 2012-05-10 16:36:42.000000000 +0200
++++ coreutils-8.17/tests/Makefile.am 2012-12-11 11:32:23.021760237 +0100
+@@ -373,6 +373,8 @@ TESTS = \
+ cp/symlink-slash \
+ cp/thru-dangling \
+ df/unreadable \
++ df/skip-duplicates \
++ df/skip-rootfs \
+ dd/direct \
+ dd/misc \
+ dd/nocache \
diff --git a/coreutils.spec b/coreutils.spec
index 679fee1..e516de1 100644
--- a/coreutils.spec
+++ b/coreutils.spec
@@ -1,7 +1,7 @@
Summary: A set of basic GNU tools commonly used in shell scripts
Name: coreutils
Version: 8.15
-Release: 8%{?dist}
+Release: 9%{?dist}
License: GPLv3+
Group: System Environment/Base
Url: http://www.gnu.org/software/coreutils/
@@ -22,6 +22,7 @@ Patch1: coreutils-8.15-cp-attribute-truncate.patch
Patch2: coreutils-8.15-du-x-nondir.patch
Patch3: coreutils-8.17-cp-freememoryread.patch
Patch4: coreutils-8.17-sort-uniq-fmr.patch
+Patch5: coreutils-8.17-df-duplicates.patch
# Our patches
#general patch to workaround koji build system issues
@@ -152,6 +153,7 @@ the old GNU fileutils, sh-utils, and textutils packages.
%patch2 -p1 -b .xnondir
%patch3 -p1 -b .cpfmr
%patch4 -p1 -b .sortfmr
+%patch5 -p1 -b .duplic
# Our patches
%patch100 -p1 -b .configure
@@ -425,6 +427,9 @@ fi
%{?!norunuser:%{_sbindir}/runuser}
%changelog
+* Wed Dec 12 2012 Ondrej Vasik <ovasik at redhat.com> 8.15-9
+- fix showing duplicates in df (#709351, O.Oprala, B.Voelker)
+
* Mon Nov 05 2012 Ondrej Vasik <ovasik at redhat.com> 8.15-8
- fix support for ecryptfs mount of "Private" in su (#722323)
- cp: avoid data-corrupting free-memory-read (upstream fix)
More information about the scm-commits
mailing list