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:
parent
7afb30e15c
commit
ba0b1bba2b
1 changed files with 10 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue