mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-10-24 02:08:57 +03:00
tests: misc: test that various commands don't fork
* 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.
This commit is contained in:
@@ -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 \
|
||||
|
||||
60
tests/misc/no-fork.sh
Executable file
60
tests/misc/no-fork.sh
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/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
|
||||
|
||||
case $host_os in
|
||||
cygwin* | mingw* | windows*)
|
||||
skip_ 'this system cannot exec without creating a new process' ;;
|
||||
esac
|
||||
|
||||
# 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
|
||||
@@ -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; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user