From 4a8707f25a8825c90987ed25906d5dfd5288aaf9 Mon Sep 17 00:00:00 2001 From: Sam Liddicott Date: Fri, 19 Apr 2013 11:04:55 +0100 Subject: [PATCH] Support setproctitle on linux with prctl(PR_SET_NAME Only the first 16 characters of the title are used on Linux systems so the most relevant data should be presented at the start of the title Signed-off-by: Sam Liddicott --- lib/replace/replace.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/replace/replace.c b/lib/replace/replace.c index 37edb31..00abad8 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -33,6 +33,11 @@ #include "system/locale.h" #include "system/wait.h" +/* Linux replacement for setproctitle */ +#if ! defined(HAVE_SETPROCTITLE) && defined(HAVE_SYS_PRCTL_H) && defined(HAVE_PRCTL) +#include +#endif + #ifdef _WIN32 #define mkdir(d,m) _mkdir(d) #endif @@ -898,5 +903,19 @@ int rep_usleep(useconds_t sec) #ifndef HAVE_SETPROCTITLE void rep_setproctitle(const char *fmt, ...) { +#if defined (HAVE_PRCTL) && defined(PR_SET_NAME) + char *title = NULL; + va_list args; + + if (fmt) { + va_start(args, fmt); + vasprintf(&title, fmt, args); + prctl(PR_SET_NAME, (unsigned long)title, 0, 0, 0); + free(title); + va_end(args); + } else { + prctl(PR_SET_NAME, 0, 0, 0, 0); + } +#endif } #endif -- 1.7.10.4 --- a/lib/replace/wscript~ 2014-09-08 11:26:14.000000000 +0200 +++ b/lib/replace/wscript 2014-10-28 22:05:54.003836383 +0100 @@ -311,8 +311,7 @@ def configure(conf): strlcpy_in_bsd = True if not conf.CHECK_FUNCS('getpeereid'): conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h') - if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'): - conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h') + conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h') if not conf.CHECK_FUNCS('setproctitle_init'): conf.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers='sys/types.h bsd/unistd.h')