Browse Source

fix setproctitle on OS X and Linux

Call the compat code and select the correct emulation mode.
Remove the string encoding support, since we have fixed inputs for the
title string.
OPENBSD_5_7
Brent Cook 10 years ago
parent
commit
6f93baf369
4 changed files with 9 additions and 6 deletions
  1. +1
    -0
      autogen.sh
  2. +5
    -6
      compat/setproctitle.c
  3. +2
    -0
      configure.ac
  4. +1
    -0
      include/stdlib.h

+ 1
- 0
autogen.sh View File

@ -3,4 +3,5 @@ set -e
./update.sh
mkdir -p m4
rm -fr autom4te.cache
autoreconf -i

+ 5
- 6
compat/setproctitle.c View File

@ -33,6 +33,7 @@
#ifndef HAVE_SETPROCTITLE
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
@ -120,7 +121,7 @@ setproctitle(const char *fmt, ...)
{
#if SPT_TYPE != SPT_NONE
va_list ap;
char buf[1024], ptitle[1024];
char buf[1024];
size_t len;
int r;
extern char *__progname;
@ -145,16 +146,14 @@ setproctitle(const char *fmt, ...)
va_end(ap);
if (r == -1 || (size_t)r >= sizeof(buf) - len)
return;
strnvis(ptitle, buf, sizeof(ptitle),
VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL);
#if SPT_TYPE == SPT_PSTAT
pst.pst_command = ptitle;
pstat(PSTAT_SETCMD, pst, strlen(ptitle), 0, 0);
pst.pst_command = buf;
pstat(PSTAT_SETCMD, pst, strlen(buf), 0, 0);
#elif SPT_TYPE == SPT_REUSEARGV
/* debug("setproctitle: copy \"%s\" into len %d",
buf, argv_env_len); */
len = strlcpy(argv_start, ptitle, argv_env_len);
len = strlcpy(argv_start, buf, argv_env_len);
for(; len < argv_env_len; len++)
argv_start[len] = SPT_PADCHAR;
#endif


+ 2
- 0
configure.ac View File

@ -35,6 +35,7 @@ case $host_os in
AC_DEFINE(BROKEN_SETREUID,[], [Broken setreuid])
AC_DEFINE(BROKEN_SETREGID,[], [Broken setregid])
AC_DEFINE(YYSTYPE_IS_DECLARED,[], [Broken bison])
AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV])
;;
*freebsd*)
HOST_OS=freebsd
@ -43,6 +44,7 @@ case $host_os in
*linux*)
HOST_OS=linux
CFLAGS="$CFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE"
AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV])
;;
*openbsd*)
AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD has __bounded__])


+ 1
- 0
include/stdlib.h View File

@ -22,6 +22,7 @@ void *reallocarray(void *, size_t, size_t);
#endif
#ifndef HAVE_SETPROCTITLE
void compat_init_setproctitle(int argc, char *argv[]);
void setproctitle(const char *fmt, ...);
#endif


Loading…
Cancel
Save