1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

tests/basic.sh: fix for 'ps' that truncates args (re: cefe087d)

This commit is contained in:
Martijn Dekker 2020-09-29 20:37:23 +02:00
parent 7afb30e15c
commit ba0b1bba2b

View file

@ -697,25 +697,29 @@ actual=$(exptest foo)
# When running a script without a #! hashbang path, ksh attempts to replace argv with the arguments
# of the script. However, fixargs() didn't wipe out the rest of previous arguments after the last
# \0. This caused an erroneous record in /proc/<PID>/cmdline and the output of the ps command.
if actual=$(UNIX95=1 ps -o args= -p "$$" 2>&1) # UNIX95=1 makes this work on HP-UX
getPsOutput() {
# UNIX95=1 makes this work on HP-UX.
actual=$(UNIX95=1 ps -o args= -p "$1" 2>&1)
# BSD 'ps' appends " (ksh)". Remove.
[[ $actual =~ \(.*\)$ ]] && actual=${actual%\(*}
# Some 'ps' implementations add leading and/or trailing whitespace. Remove.
while [[ $actual == [[:space:]]* ]]; do actual=${actual#?}; done
while [[ $actual == *[[:space:]] ]]; do actual=${actual%?}; done
[[ $actual == "$SHELL $0" ]] # this is how shtests invokes this script
}
if getPsOutput "$$"
[[ "$SHELL $0" == "$actual"* ]] # "$SHELL $0" is how shtests invokes this script
then expect='./atest 1 2'
echo 'sleep 10; exit 0' >atest
chmod 755 atest
./atest 1 2 &
actual=$(UNIX95=1 ps -o args= -p "$!")
getPsOutput "$!"
kill "$!"
[[ $actual =~ \(.*\)$ ]] && actual=${actual%\(*} # BSD 'ps' adds " (ksh)"
while [[ $actual == [[:space:]]* ]]; do actual=${actual#?}; done
while [[ $actual == *[[:space:]] ]]; do actual=${actual%?}; done
[[ $actual == "$expect" ]] || err_exit "ksh didn't rewrite argv correctly" \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
else err_exit "warning: skipping argv rewrite test due to noncompliant 'ps' utility (got $(printf %q "$actual"))"
let Errors--
fi
unset -f getPsOutput
# ======
# https://bugzilla.redhat.com/1241013