* tests/misc/no-fork.sh: New file.
* tests/local.mk (all_tests): Add the new test.
* tests/misc/stdbuf.sh: Remove a test that is redundant with the new
test.
---
 tests/local.mk        |  1 +
 tests/misc/no-fork.sh | 55 +++++++++++++++++++++++++++++++++++++++++++
 tests/misc/stdbuf.sh  |  3 ---
 3 files changed, 56 insertions(+), 3 deletions(-)
 create mode 100755 tests/misc/no-fork.sh

diff --git a/tests/local.mk b/tests/local.mk
index 5be625f8a..d6a9b8504 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -185,6 +185,7 @@ all_tests =                                 \
   tests/misc/io-errors.sh                      \
   tests/misc/read-errors.sh                    \
   tests/misc/responsive.sh                     \
+  tests/misc/no-fork.sh                                \
   tests/misc/traversal-missing.sh              \
   tests/misc/tty-quoting.sh                    \
   tests/misc/uname-labeled.sh                  \
diff --git a/tests/misc/no-fork.sh b/tests/misc/no-fork.sh
new file mode 100755
index 000000000..c1efd1889
--- /dev/null
+++ b/tests/misc/no-fork.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# Test that various utilities do not fork a child process before
+# executing another program.
+
+# Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ true
+
+# List of programs that should not fork a child process.
+printf '%s' '\
+chroot --skip-chdir / true
+env true
+nice true
+nohup true
+runcon "$(id -Z)" true
+stdbuf -oL true
+' |
+sort -k 1b,1 > all_executors || framework_failure_
+
+printf '%s\n' $built_programs |
+sort -k 1b,1 > built_programs || framework_failure_
+
+join all_executors built_programs > built_executors || framework_failure_
+
+while read executor; do
+  executor=$(eval $executor)
+  (ulimit -u 0; exec $executor) 2>err ||
+    case "$executor" in
+      runcon*)
+        grep 'runcon: runcon may be used only on a SELinux kernel' err
+        ;;
+      chroot*)
+        ! uid_is_privileged_
+        ;;
+      *)
+        false
+        ;;
+    esac || { cat err; fail=1; }
+done < built_executors
+
+Exit $fail
diff --git a/tests/misc/stdbuf.sh b/tests/misc/stdbuf.sh
index 79d15b374..170d25c5f 100755
--- a/tests/misc/stdbuf.sh
+++ b/tests/misc/stdbuf.sh
@@ -55,9 +55,6 @@ stdbuf -i0 -o0 -e0 true || fail=1 #check all files
 returns_ 126 env . && { returns_ 126 stdbuf -o1 . || fail=1; } # invalid 
command
 returns_ 127 stdbuf -o1 no_such || fail=1 # no such command
 
-# Test that 'stdbuf' doesn't create a child process.
-(ulimit -u 0; exec stdbuf -oL true) || fail=1
-
 # Terminate any background processes
 cleanup_() { kill $pid 2>/dev/null && wait $pid; }
 
-- 
2.55.0


Reply via email to