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

main.c: fixargs(): add support for *BSD using setproctitle(3)

What is this for? See cefe087d

src/cmd/ksh93/Mamfile:
- Make iffe generate a test for the presence of setproctitle(3).

src/cmd/ksh93/sh/main.c:
- Include setproctitle test result.
- Re-enable fixargs() for FreeBSD and DragonFly BSD.
  Disable it for UnixWare.
- fixargs(): Add _lib_setproctitle version. Keep it simple with a
  128-character buffer array -- should be plenty for 'ps' output.
- fixargs(): Fix an off-by-one in zeroing the rest of the buffer.

src/cmd/ksh93/tests/basic.sh:
- Update the relevant regression test to run on FreeBSD/DragonFly
  and tolerate the "ksh: " prefix added by setproctitle(3).
This commit is contained in:
Martijn Dekker 2021-01-21 22:23:28 +01:00
parent 7fdeadd4f1
commit 47468f56c2
3 changed files with 22 additions and 7 deletions

View file

@ -705,13 +705,14 @@ actual=$(exptest foo)
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%\(*}
# BSD: setproctitle(3) prepends "ksh:" and ps(1) appends " (ksh)". Remove.
actual=${actual#'ksh: '}
actual=${actual%' (ksh)'}
# Some 'ps' implementations add leading and/or trailing whitespace. Remove.
while [[ $actual == [[:space:]]* ]]; do actual=${actual#?}; done
while [[ $actual == *[[:space:]] ]]; do actual=${actual%?}; done
}
if [[ ! $(uname -s) =~ ^(FreeBSD|DragonFly|SunOS)$ ]] &&
if [[ ! $(uname -s) =~ ^(SunOS|UnixWare)$ ]] &&
getPsOutput "$$" &&
[[ "$SHELL $0" == "$actual"* ]] # "$SHELL $0" is how shtests invokes this script
then expect='./atest 1 2'