Skip to content

Commit

Permalink
main.c: Tweak fixargs() (re: cefe087)
Browse files Browse the repository at this point in the history
src/cmd/ksh93/sh/main.c: fixargs():
- Erase the entire length of the command arguments buffer (the
  space from argv[0] until environ[0]) so that remnants of longer
  command arguments aren't left in 'ps' output when executing a
  hashbang-ess script with a shorter command line.
- Disable fixargs() on FreeBSD. It has never had any effect on that
  system; apparently it either requires another method to rewrite
  arguments for 'ps' output purposes (which?) or it's not possible.

src/cmd/ksh93/tests/basic.sh:
- Skip the test if running on FreeBSD.
  • Loading branch information
McDutchie committed Jan 10, 2021
1 parent e720283 commit 159fb9e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/cmd/ksh93/sh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
/* These routines are referenced by this module */
static void exfile(Shell_t*, Sfio_t*,int);
static void chkmail(Shell_t *shp, char*);
#if defined(_lib_fork) && !defined(_NEXT_SOURCE)
#if defined(_lib_fork) && !defined(_NEXT_SOURCE) && !defined(__FreeBSD__)
static void fixargs(char**,int);
#else
# define fixargs(a,b)
Expand Down Expand Up @@ -697,7 +697,7 @@ static void chkmail(Shell_t *shp, char *files)
# define PSTAT 1
#endif

#if defined(_lib_fork) && !defined(_NEXT_SOURCE)
#if defined(_lib_fork) && !defined(_NEXT_SOURCE) && !defined(__FreeBSD__)
/*
* fix up command line for ps command
*
Expand Down Expand Up @@ -735,9 +735,7 @@ static void fixargs(char **argv, int mode)
if(mode==0)
{
buff = argv[0];
while(cp = *argv++)
command_len += strlen(cp)+1;
command_len -= 1;
command_len = environ[0] - buff - 1;
return;
}
# endif /* PSTAT */
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/ksh93/tests/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ getPsOutput() {
while [[ $actual == [[:space:]]* ]]; do actual=${actual#?}; done
while [[ $actual == *[[:space:]] ]]; do actual=${actual%?}; done
}
if getPsOutput "$$"
if [[ $(uname -s) != FreeBSD ]] &&
getPsOutput "$$" &&
[[ "$SHELL $0" == "$actual"* ]] # "$SHELL $0" is how shtests invokes this script
then expect='./atest 1 2'
echo 'sleep 10; exit 0' >atest
Expand All @@ -718,8 +719,6 @@ then expect='./atest 1 2'
kill "$!"
[[ $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
Expand Down

0 comments on commit 159fb9e

Please sign in to comment.