bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

df / no longer outputs a header


From: Paul Eggert
Subject: df / no longer outputs a header
Date: Tue, 15 Aug 2006 16:44:37 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

One thing we noticed right away when putting coreutils 6.0 in a place
where others could use it is that "df /usr" no longer outputs a
header.  This change isn't intended, surely.  While fixing this I
noticed that the new behavior of exiting with nonzero status when
ther's no output isn't documented.  So I documented that, and
installed this combined change:

2006-08-15  Paul Eggert  <address@hidden>

        * NEWS: Mention that df exits with nonzero status if it generates
        no output.  This change was in 6.0 but inadvertently unmentioned.
        * doc/coreutils.texi (df invocation): df exits nonzero if it outpus
        nothing.
        * src/df.c (file_systems_processed): Renamed from n_valid_args, and now
        a boolean.
        (show_dev): Don't set it until we actually output something.
        Print the header if this is the first output.
        (main): Don't print a header, as that is now show_dev's job.
        * tests/misc/Makefile.am (TESTS): Add df.
        * tests/misc/df: New file.

Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.399
diff -p -u -r1.399 NEWS
--- NEWS        15 Aug 2006 17:00:00 -0000      1.399
+++ NEWS        15 Aug 2006 23:40:30 -0000
@@ -59,10 +59,16 @@ GNU coreutils NEWS                      
   date: a command like date -d '2006-04-23 21 days ago' would print
   the wrong date in some time zones.  (see the test for an example)
 
-  df now considers "none" and "proc" file systems to be dummies and
-  therefore does not normally display them.  Also, inaccessible file
-  systems (which can be caused by shadowed mount points or by chrooted
-  bind mounts) are now dummies, too.
+  df changes:
+
+    df now considers "none" and "proc" file systems to be dummies and
+    therefore does not normally display them.  Also, inaccessible file
+    systems (which can be caused by shadowed mount points or by
+    chrooted bind mounts) are now dummies, too.
+
+    df now fails if it generates no output, so you can inspect the
+    exit status of a command like "df -t ext3 -t reiserfs DIR" to test
+    whether DIR is on a file system of type "ext3" or "reiserfs".
 
   expr no longer complains about leading ^ in a regular expression
   (the anchor is ignored), or about regular expressions like A** (the
Index: doc/coreutils.texi
===================================================================
RCS file: /fetish/cu/doc/coreutils.texi,v
retrieving revision 1.345
diff -p -u -r1.345 coreutils.texi
--- doc/coreutils.texi  9 Aug 2006 21:16:28 -0000       1.345
+++ doc/coreutils.texi  15 Aug 2006 23:40:32 -0000
@@ -9426,6 +9426,10 @@ Ignored; for compatibility with System V
 @end table
 
 @exitstatus
+Failure includes the case where no output is generated, so you can
+inspect the exit status of a command like @samp{df -t ext3 -t reiserfs
address@hidden to test whether @var{dir} is on a file system of type
address@hidden or @samp{reiserfs}.
 
 
 @node du invocation
Index: src/df.c
===================================================================
RCS file: /fetish/cu/src/df.c,v
retrieving revision 1.174
diff -p -u -r1.174 df.c
--- src/df.c    25 Jul 2006 14:06:21 -0000      1.174
+++ src/df.c    15 Aug 2006 23:40:32 -0000
@@ -68,8 +68,8 @@ static uintmax_t output_block_size;
 /* If true, use the POSIX output format.  */
 static bool posix_format;
 
-/* Count the number of valid arguments.  */
-static unsigned int n_valid_args;
+/* True if a file system has been processed for output.  */
+static bool file_systems_processed;
 
 /* If true, invoke the `sync' system call before getting any usage data.
    Using this option can make df very slow, especially with many or very
@@ -295,8 +295,6 @@ show_dev (char const *disk, char const *
   if (!selected_fstype (fstype) || excluded_fstype (fstype))
     return;
 
-  ++n_valid_args;
-
   /* 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,
@@ -314,6 +312,12 @@ show_dev (char const *disk, char const *
   if (fsu.fsu_blocks == 0 && !show_all_fs && !show_listed_fs)
     return;
 
+  if (! file_systems_processed)
+    {
+      file_systems_processed = true;
+      print_header ();
+    }
+
   if (! disk)
     disk = "-";                        /* unknown */
   if (! fstype)
@@ -786,6 +790,7 @@ main (int argc, char **argv)
                                     &output_block_size);
 
   print_type = false;
+  file_systems_processed = false;
   posix_format = false;
   exit_status = EXIT_SUCCESS;
 
@@ -928,20 +933,14 @@ main (int argc, char **argv)
       /* Display explicitly requested empty file systems. */
       show_listed_fs = true;
 
-      if (n_valid_args > 0)
-       print_header ();
-
       for (i = optind; i < argc; ++i)
        if (argv[i])
          show_entry (argv[i], &stats[i - optind]);
     }
   else
-    {
-      print_header ();
-      show_all_entries ();
-    }
+    show_all_entries ();
 
-  if (n_valid_args == 0)
+  if (! file_systems_processed)
     error (EXIT_FAILURE, 0, _("no file systems processed"));
 
   exit (exit_status);
Index: tests/misc/Makefile.am
===================================================================
RCS file: /fetish/cu/tests/misc/Makefile.am,v
retrieving revision 1.42
diff -p -u -r1.42 Makefile.am
--- tests/misc/Makefile.am      8 Aug 2006 22:20:59 -0000       1.42
+++ tests/misc/Makefile.am      15 Aug 2006 23:40:32 -0000
@@ -27,6 +27,7 @@ TESTS = \
   csplit \
   date \
   date-sec \
+  df \
   dirname \
   expand \
   false-status \
--- /dev/null   2005-09-24 22:00:15.000000000 -0700
+++ tests/misc/df       2006-08-15 16:39:39.000000000 -0700
@@ -0,0 +1,17 @@
+#!/bin/sh
+# Ensure that "df ." outputs a header.
+
+if test "$VERBOSE" = yes; then
+  set -x
+  df --version
+fi
+
+case `df .` in
+*'
+'*)
+  fail=0;;
+*)
+  fail=1;;
+esac
+
+(exit $fail); exit $fail





reply via email to

[Prev in Thread] Current Thread [Next in Thread]