]>
Commit | Line | Data |
---|---|---|
cc54fa40 AM |
1 | From 4a8707f25a8825c90987ed25906d5dfd5288aaf9 Mon Sep 17 00:00:00 2001 |
2 | From: Sam Liddicott <sam@liddicott.com> | |
3 | Date: Fri, 19 Apr 2013 11:04:55 +0100 | |
4 | Subject: [PATCH] Support setproctitle on linux with prctl(PR_SET_NAME | |
5 | ||
6 | Only the first 16 characters of the title are used on Linux systems | |
7 | so the most relevant data should be presented at the start of the | |
8 | title | |
9 | ||
10 | Signed-off-by: Sam Liddicott <sam@liddicott.com> | |
11 | --- | |
12 | lib/replace/replace.c | 19 +++++++++++++++++++ | |
13 | 1 file changed, 19 insertions(+) | |
14 | ||
15 | diff --git a/lib/replace/replace.c b/lib/replace/replace.c | |
16 | index 37edb31..00abad8 100644 | |
17 | --- a/lib/replace/replace.c | |
18 | +++ b/lib/replace/replace.c | |
19 | @@ -33,6 +33,11 @@ | |
20 | #include "system/locale.h" | |
21 | #include "system/wait.h" | |
22 | ||
23 | +/* Linux replacement for setproctitle */ | |
24 | +#if ! defined(HAVE_SETPROCTITLE) && defined(HAVE_SYS_PRCTL_H) && defined(HAVE_PRCTL) | |
25 | +#include <sys/prctl.h> | |
26 | +#endif | |
27 | + | |
28 | #ifdef _WIN32 | |
29 | #define mkdir(d,m) _mkdir(d) | |
30 | #endif | |
31 | @@ -898,5 +903,19 @@ int rep_usleep(useconds_t sec) | |
32 | #ifndef HAVE_SETPROCTITLE | |
33 | void rep_setproctitle(const char *fmt, ...) | |
34 | { | |
35 | +#if defined (HAVE_PRCTL) && defined(PR_SET_NAME) | |
36 | + char *title = NULL; | |
37 | + va_list args; | |
38 | + | |
39 | + if (fmt) { | |
40 | + va_start(args, fmt); | |
41 | + vasprintf(&title, fmt, args); | |
42 | + prctl(PR_SET_NAME, (unsigned long)title, 0, 0, 0); | |
43 | + free(title); | |
44 | + va_end(args); | |
45 | + } else { | |
46 | + prctl(PR_SET_NAME, 0, 0, 0, 0); | |
47 | + } | |
48 | +#endif | |
49 | } | |
50 | #endif | |
51 | -- | |
52 | 1.7.10.4 | |
53 | ||
54 | --- a/lib/replace/wscript~ 2014-09-08 11:26:14.000000000 +0200 | |
55 | +++ b/lib/replace/wscript 2014-10-28 22:05:54.003836383 +0100 | |
baa92be6 | 56 | @@ -251,8 +251,7 @@ def configure(conf): |
cc54fa40 AM |
57 | checklibc=True) |
58 | if not conf.CHECK_FUNCS('getpeereid'): | |
59 | conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h') | |
baa92be6 AM |
60 | - if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'): |
61 | - conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h') | |
cc54fa40 AM |
62 | + conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h') |
63 | ||
64 | conf.CHECK_CODE(''' | |
65 | struct ucred cred; | |
baa92be6 | 66 |