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

@ -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 */
}