diff --git a/src/cmd/ksh93/tests/basic.sh b/src/cmd/ksh93/tests/basic.sh index c9beee7e0..dd7029ff4 100755 --- a/src/cmd/ksh93/tests/basic.sh +++ b/src/cmd/ksh93/tests/basic.sh @@ -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//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