From 46afefaaa8ea95b5eb63a62792774cd18738234a Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Tue, 14 Aug 2012 09:22:13 +0200 Subject: 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. --- src/df.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/df.c') 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")); } -- cgit v1.2.3-54-g00ecf