coreutils
[Top][All Lists]
Advanced

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

[PATCH] df: fix exit code and ensure printing "unprocessed" msg when tot


From: Bernhard Voelker
Subject: [PATCH] df: fix exit code and ensure printing "unprocessed" msg when totaling
Date: Sat, 04 Aug 2012 01:11:48 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0

sorry for the long subject.

Have a nice day,
Berny

>From e3978a7c2cd0f6da265f62809cf82174cd03d431 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Sat, 4 Aug 2012 01:09:22 +0200
Subject: [PATCH] df: fix exit code and ensure printing "unprocessed" msg when
 totaling

When the combination of the file system options with given files or
devices does not lead to output, "df --total" would exit successfully
although it should not.

Examples:
  $ df --total --type=xfs /          # when / is not an XFS file system
  $ df --total --local -t nfs  DIR   # nfs is remote per se ...
  $ df --total -t qwerty /dev/sdb5   # typo in file system type

Furthermore, "df --total" would not print the error message "no file
systems processed" when the file argument does not exist or is otherwise
not accessible.

Example:
  $ df --total __not_exist__

These 2 bugs are present since --total was added by commit
v6.12-166-gea2887b.

* src/df.c (get_dev): Do not set file_systems_processed to true when
force_fsu is true, i.e. when the row for the "total" line is processed.
* tests/df/total-unprocessed: Add a new test.
* tests/Makefile.am: Reference the new test.
* NEWS: Mention the fix.
---
 NEWS                       |    7 +++++++
 src/df.c                   |    3 ++-
 tests/Makefile.am          |    1 +
 tests/df/total-unprocessed |   38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 1 deletions(-)
 create mode 100755 tests/df/total-unprocessed

diff --git a/NEWS b/NEWS
index f1255ea..2ad5fc2 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,13 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   lines output by df, can work reliably.
   [This bug was present in "the beginning".]

+  df --total would exit 0 when the include/exclude FS options do not
+  lead to a processed file system. Now it exits with the appropriate
+  error code.
+  Furthermore, df --total would not print "no file systems processed"
+  when it should.
+  [This bug dates back to when --total was added in coreutils-7.0]
+
   head --lines=-N (-n-N) now resets the read pointer of a seekable input file.
   This means that "head -n-3" no longer consumes all of its input, and lines
   not output by head may be processed by other programs.  For example, this
diff --git a/src/df.c b/src/df.c
index 5dc3d2d..f7e481e 100644
--- a/src/df.c
+++ b/src/df.c
@@ -515,7 +515,8 @@ get_dev (char const *disk, char const *mount_point,

   if (! file_systems_processed)
     {
-      file_systems_processed = true;
+      if (! force_fsu)
+        file_systems_processed = true;
       get_header ();
     }

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4e7ea58..edc04b4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -375,6 +375,7 @@ TESTS =                                             \
   df/header                                    \
   df/df-P                                      \
   df/unreadable                                        \
+  df/total-unprocessed                         \
   dd/direct                                    \
   dd/misc                                      \
   dd/nocache                                   \
diff --git a/tests/df/total-unprocessed b/tests/df/total-unprocessed
new file mode 100755
index 0000000..f4b9934
--- /dev/null
+++ b/tests/df/total-unprocessed
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Ensure that df exits non-Zero and writes an error message when
+# --total is used but no filesystem has been processed.
+
+
+# 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
+
+cat <<\EOF > exp || fail=1
+df: no file systems processed
+EOF
+
+# The following simply finds no match for the combination
+# of the options --local and FS-type nfs together with the
+# argument ".". It must exit non-Zero nonetheless.
+df --local -t nfs --total "." 2>out && fail=1
+compare exp out || fail=1
+
+# Ensure that df writes the error message also in the following case.
+df --total _does_not_exist_ 2>out2 && fail=1
+compare exp out2 || fail=1
+
+Exit $fail
-- 
1.7.7





reply via email to

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