From a5726f2f53f3560e0bfe4bf75acf79b2e61f35b6 Mon Sep 17 00:00:00 2001 From: =?latin1?q?P=E1draig=20Brady?= Date: Sun, 5 Apr 2015 18:21:38 +0100 Subject: df: fix --local hanging with inaccessible remote mounts * src/df.c (filter_mount_list): With -l, avoid stating remote mounts. * init.cfg: Avoid test hangs with inaccessible remote mounts. * tests/df/no-mtab-status.sh: Skip with inaccessible remote mounts. * tests/df/skip-rootfs.sh: Likewise. * tests/df/total-verify.sh: Likewise. * NEWS: Mention the bug fix. Reported at http://bugzilla.redhat.com/1199679 (cherry picked from commit 1b1c40e1d6f8cf30b6c7c9d31bbddbc3d5cc72e6) Conflicts: NEWS --- init.cfg | 2 +- src/df.c | 9 ++++++--- tests/df/no-mtab-status.sh | 3 ++- tests/df/skip-rootfs.sh | 3 ++- tests/df/total-verify.sh | 3 ++- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/init.cfg b/init.cfg index 032646b..527e5fa 100644 --- a/init.cfg +++ b/init.cfg @@ -79,7 +79,7 @@ is_local_dir_() require_mount_list_() { local mount_list_fail='cannot read table of mounted file systems' - df 2>&1 | grep -F "$mount_list_fail" >/dev/null && + df --local 2>&1 | grep -F "$mount_list_fail" >/dev/null && skip_ "$mount_list_fail" } diff --git a/src/df.c b/src/df.c index 9d1b6bb..81c047d 100644 --- a/src/df.c +++ b/src/df.c @@ -622,13 +622,16 @@ filter_mount_list (bool devices_only) struct devlist *devlist; struct mount_entry *discard_me = NULL; - /* TODO: On Linux we might avoid this stat() and another in get_dev() + /* Avoid stating remote file systems as that may hang. + TODO: On Linux we might avoid this stat() and another in get_dev() by using the device IDs available from /proc/self/mountinfo. read_file_system_list() could populate me_dev from those for efficiency and accuracy. */ - if (-1 == stat (me->me_mountdir, &buf)) + if ((me->me_remote && show_local_fs) + || -1 == stat (me->me_mountdir, &buf)) { - /* Stat failed - add ME to be able to complain about it later. */ + /* If remote, and showing just local, add ME for filtering later. + If stat failed; add ME to be able to complain about it later. */ buf.st_dev = me->me_dev; } else diff --git a/tests/df/no-mtab-status.sh b/tests/df/no-mtab-status.sh index 9ea2036..86840e2 100755 --- a/tests/df/no-mtab-status.sh +++ b/tests/df/no-mtab-status.sh @@ -21,7 +21,8 @@ print_ver_ df require_gcc_shared_ -df || skip_ "df fails" +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \ || skip_ "no mntent.h available to confirm the interface" diff --git a/tests/df/skip-rootfs.sh b/tests/df/skip-rootfs.sh index 94f32c6..461ea54d 100755 --- a/tests/df/skip-rootfs.sh +++ b/tests/df/skip-rootfs.sh @@ -19,7 +19,8 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ df -df || skip_ "df fails" +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" # Verify that rootfs is in mtab (and shown when the -a option is specified). df -a >out || fail=1 diff --git a/tests/df/total-verify.sh b/tests/df/total-verify.sh index 63cbe8f..3f71dd6 100755 --- a/tests/df/total-verify.sh +++ b/tests/df/total-verify.sh @@ -20,7 +20,8 @@ print_ver_ df require_perl_ -df || skip_ "df fails" +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" cat <<\EOF > check-df || framework_failure_ my ($total, $used, $avail) = (0, 0, 0); -- 1.7.12.1