From: oech3 <79379754+oech3@users.noreply.github.com> Date: Tue, 30 Dec 2025 12:03:11 +0000 (+0900) Subject: tests: df: hide /proc without using LD_PRELOAD X-Git-Tag: v9.10~147 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=92a93c445b67cf04315f18a25801491b60bd5c38;p=thirdparty%2Fcoreutils.git tests: df: hide /proc without using LD_PRELOAD * tests/df/no-mtab-status-masked-proc.sh: A new test similar to no-mtab-status.sh but should work with static builds. * tests/local.mk: Reference the new test. https://github.com/coreutils/coreutils/pull/156 --- diff --git a/tests/df/no-mtab-status-masked-proc.sh b/tests/df/no-mtab-status-masked-proc.sh new file mode 100755 index 0000000000..52c2951aaf --- /dev/null +++ b/tests/df/no-mtab-status-masked-proc.sh @@ -0,0 +1,67 @@ +#!/bin/sh +# Test df's behavior when /proc cannot be read. +# This is an alternative for no-mtab-status.sh for static binaries. +# This test is skipped if User namespace sandbox is unavailable. + +# Copyright (C) 2025 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"; path_prepend_ ./src +print_ver_ df +skip_if_root_ + +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" + +unshare -rm true || skip_ 'User namespace sandbox is disabled' + +# mask /proc +df() { + unshare -rm bash -c \ + "mount -t tmpfs tmpfs /proc && command df \"\$@\"" -- "$@"; +} + +df /proc || fail=1 +returns_ 1 df /proc/self || framework_failure_ + +# Keep the following in sync with no-mtab-status.sh + +# These tests are supposed to succeed: +df '.' || fail=1 +df -i '.' || fail=1 +df -T '.' || fail=1 +df -Ti '.' || fail=1 +df --total '.' || fail=1 + +# These tests are supposed to fail: +returns_ 1 df || fail=1 +returns_ 1 df -i || fail=1 +returns_ 1 df -T || fail=1 +returns_ 1 df -Ti || fail=1 +returns_ 1 df --total || fail=1 + +returns_ 1 df -a || fail=1 +returns_ 1 df -a '.' || fail=1 + +returns_ 1 df -l || fail=1 +returns_ 1 df -l '.' || fail=1 + +returns_ 1 df -t hello || fail=1 +returns_ 1 df -t hello '.' || fail=1 + +returns_ 1 df -x hello || fail=1 +returns_ 1 df -x hello '.' || fail=1 + +Exit $fail diff --git a/tests/local.mk b/tests/local.mk index 33527d3795..fb85bf384f 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -581,6 +581,7 @@ all_tests = \ tests/df/unreadable.sh \ tests/df/total-unprocessed.sh \ tests/df/no-mtab-status.sh \ + tests/df/no-mtab-status-masked-proc.sh \ tests/df/skip-duplicates.sh \ tests/df/skip-rootfs.sh \ tests/dd/ascii.sh \