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

@ -623,6 +623,10 @@ make FEATURE/pstat implicit
meta FEATURE/pstat >FEATURE/% pstat
exec - iffe -v -c '${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} ' ref ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdll} ${mam_libcmd} ${mam_libast} ${mam_libm} ${mam_libnsl} : def pstat
done FEATURE/pstat generated
make FEATURE/setproctitle implicit
meta FEATURE/setproctitle >FEATURE/% setproctitle
exec - iffe -v -c '${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} ' ref ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdll} ${mam_libcmd} ${mam_libast} ${mam_libm} ${mam_libnsl} : def setproctitle
done FEATURE/setproctitle generated
prev FEATURE/time implicit
make include/timeout.h implicit
done include/timeout.h

View file

@ -43,6 +43,7 @@
#include "timeout.h"
#include "FEATURE/time"
#include "FEATURE/pstat"
#include "FEATURE/setproctitle"
#include "FEATURE/execargs"
#include "FEATURE/externs"
#ifdef _hdr_nc
@ -52,7 +53,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) && !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__sun)
#if defined(_lib_fork) && !defined(_NEXT_SOURCE) && !defined(__USLC__) && !defined(__sun)
static void fixargs(char**,int);
#else
# define fixargs(a,b)
@ -714,11 +715,11 @@ static void fixargs(char **argv, int mode)
#if EXECARGS
*execargs=(char *)argv;
#else
static char *buff;
static int command_len;
register char *cp;
int offset=0,size;
# ifdef PSTAT
static int command_len;
char *buff;
union pstun un;
if(mode==0)
{
@ -731,7 +732,14 @@ static void fixargs(char **argv, int mode)
}
stakseek(command_len+2);
buff = stakseek(0);
# elif _lib_setproctitle
# define command_len 255
char buff[command_len + 1];
if(mode==0)
return;
# else
static int command_len;
static char *buff;
if(mode==0)
{
buff = argv[0];
@ -750,10 +758,12 @@ static void fixargs(char **argv, int mode)
buff[offset++] = ' ';
}
offset--;
memset(&buff[offset], 0, command_len - offset);
memset(&buff[offset], 0, command_len - offset + 1);
# ifdef PSTAT
un.pst_command = stakptr(0);
pstat(PSTAT_SETCMD,un,0,0,0);
# elif _lib_setproctitle
setproctitle("%s",buff);
# endif /* PSTAT */
#endif /* EXECARGS */
}

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'