Skip to content

Commit

Permalink
tests/basic.sh: fix for 'ps' that truncates args (re: cefe087)
Browse files Browse the repository at this point in the history
  • Loading branch information
McDutchie committed Sep 29, 2020
1 parent 7afb30e commit ba0b1bb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/cmd/ksh93/tests/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba0b1bb

Please sign in to comment.