summaryrefslogtreecommitdiff
path: root/src/df.c
diff options
context:
space:
mode:
authorBernhard Voelker <mail@bernhard-voelker.de>2012-08-14 09:22:13 +0200
committerJim Meyering <meyering@redhat.com>2012-08-14 11:34:54 +0200
commit46afefaaa8ea95b5eb63a62792774cd18738234a (patch)
tree4d76b669c082df105808d05af462652923d70258 /src/df.c
parenta07dfa9064bf80b4ceea7048c3104495797a6668 (diff)
downloadcoreutils-46afefaaa8ea95b5eb63a62792774cd18738234a.tar.xz
df: fail when the mount list is required but cannot be read
* src/df.c (main): Add conditions to fail when the mount list cannot be read: this includes the cases when a file name argument is given and any of -a, -l, -t or -x is used. * doc/coreutils.texi: Document the additional error conditions. * tests/df/no-mtab-status: Add a new test. * tests/Makefile.am: Reference the new test. * NEWS: Mention the fix.
Diffstat (limited to 'src/df.c')
-rw-r--r--src/df.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/df.c b/src/df.c
index 4f3b56b25..9d956cd03 100644
--- a/src/df.c
+++ b/src/df.c
@@ -1100,10 +1100,19 @@ main (int argc, char **argv)
if (mount_list == NULL)
{
/* Couldn't read the table of mounted file systems.
- Fail if df was invoked with no file name arguments;
- Otherwise, merely give a warning and proceed. */
- int status = (optind < argc ? 0 : EXIT_FAILURE);
- const char *warning = (optind < argc ? _("Warning: ") : "");
+ Fail if df was invoked with no file name arguments,
+ or when either of -a, -l, -t or -x is used with file name
+ arguments. Otherwise, merely give a warning and proceed. */
+ int status = 0;
+ if ( ! (optind < argc)
+ || (show_all_fs
+ || show_local_fs
+ || fs_select_list != NULL
+ || fs_exclude_list != NULL))
+ {
+ status = EXIT_FAILURE;
+ }
+ const char *warning = (status == 0 ? _("Warning: ") : "");
error (status, errno, "%s%s", warning,
_("cannot read table of mounted file systems"));
}