>From a8700d7e24e47c366f19dbd58a186432535d6702 Mon Sep 17 00:00:00 2001
From: Fridolin Pokorny
Date: Tue, 2 Sep 2014 14:04:43 +0200
Subject: [PATCH 2/2] df: add a test for /proc/self/mountinfo support
* tests/df/chroot.sh: Add a test case.
* tests/df/no-mtab-status.sh: Skip this test
when /proc/self/mountinfo is supported.
* tests/local.mk (all_root_tests): Mention the test.
---
tests/df/chroot.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++
tests/df/no-mtab-status.sh | 3 +++
tests/local.mk | 1 +
3 files changed, 63 insertions(+)
create mode 100755 tests/df/chroot.sh
diff --git a/tests/df/chroot.sh b/tests/df/chroot.sh
new file mode 100755
index 0000000..ca33d5f
--- /dev/null
+++ b/tests/df/chroot.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# make sure 'df' uses /proc/self/mountinfo if available
+
+# Copyright (C) 2000-2014 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 .
+
+. "${srcdir=.}/tests/init.sh"
+print_ver_ df
+require_root_
+
+cleanup_() {
+ umount lib
+ [ -d lib64 ] && umount lib64
+}
+
+grep '^#define MOUNTED_PROC_MOUNTINFO 1' $CONFIG_HEADER > /dev/null \
+ || skip_ "/proc/self/mountinfo is not supported"
+
+mkdir lib || framework_failure_
+mount --bind /lib lib || framework_failure_
+[ -d /lib64 ] && {
+ mkdir lib64 || framework_failure_
+ mount --bind /lib64 lib64 || framework_failure_
+}
+
+# place binary into chroot
+cp "$abs_top_builddir/src/df" df || framework_failure_
+
+# nothing to read
+chroot . ./df -a && fail=1
+
+# df should always use /proc/self/mountinfo, there's no /etc/mtab
+mkdir -p proc/self/ || framework_failure_
+cat <<\EOF > proc/self/mountinfo || framework_failure_
+36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
+EOF
+chroot . ./df -a || fail=1
+
+# fallback - /etc/mtab
+rm -f proc/self/mountinfo
+mkdir etc/
+cat <<\EOF > etc/mtab || framework_failure_
+/ /mnt ext3 rw,noatime 0 0
+EOF
+chroot . ./df -a || fail=1
+
+Exit $fail
diff --git a/tests/df/no-mtab-status.sh b/tests/df/no-mtab-status.sh
index 9ea2036..fcf589d 100755
--- a/tests/df/no-mtab-status.sh
+++ b/tests/df/no-mtab-status.sh
@@ -29,6 +29,9 @@ grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \
grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \
|| skip_ "getmntent is not used on this system"
+grep '^#define MOUNTED_PROC_MOUNTINFO 1' $CONFIG_HEADER > /dev/null \
+ && skip_ "configured to use /proc/self/mountinfo"
+
# Simulate "mtab" failure.
cat > k.c <<'EOF' || framework_failure_
#include
diff --git a/tests/local.mk b/tests/local.mk
index e0f1f84..5c2d956 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -116,6 +116,7 @@ all_root_tests = \
tests/dd/skip-seek-past-dev.sh \
tests/df/problematic-chars.sh \
tests/df/over-mount-device.sh \
+ tests/df/chroot.sh \
tests/du/bind-mount-dir-cycle.sh \
tests/id/setgid.sh \
tests/install/install-C-root.sh \
--
1.9.3