From 6f93baf3690a7a16df5b9f243889af4c1a63310d Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 12 Jan 2015 21:55:14 -0600 Subject: [PATCH] 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. --- autogen.sh | 1 + compat/setproctitle.c | 11 +++++------ configure.ac | 2 ++ include/stdlib.h | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/autogen.sh b/autogen.sh index 025119c..825bccd 100755 --- a/autogen.sh +++ b/autogen.sh @@ -3,4 +3,5 @@ set -e ./update.sh mkdir -p m4 +rm -fr autom4te.cache autoreconf -i diff --git a/compat/setproctitle.c b/compat/setproctitle.c index 7742e98..f206435 100644 --- a/compat/setproctitle.c +++ b/compat/setproctitle.c @@ -33,6 +33,7 @@ #ifndef HAVE_SETPROCTITLE +#include #include #include #include @@ -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 diff --git a/configure.ac b/configure.ac index 13fbdfa..b500c7d 100644 --- a/configure.ac +++ b/configure.ac @@ -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__]) diff --git a/include/stdlib.h b/include/stdlib.h index 46e4b03..b3b656e 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -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