From: Roy Marples Date: Tue, 15 Oct 2019 11:39:44 +0000 (+0300) Subject: compat: Fix setproctitle on Solaris X-Git-Tag: v8.1.1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e52d6a442580d983d38c800797076a0bf458c441;p=thirdparty%2Fdhcpcd.git compat: Fix setproctitle on Solaris --- diff --git a/compat/setproctitle.c b/compat/setproctitle.c index 9350e5ee..c1d4d705 100644 --- a/compat/setproctitle.c +++ b/compat/setproctitle.c @@ -30,24 +30,28 @@ #include #include "config.h" +#include "dhcpcd.h" #ifdef __sun #define SETPROCTITLE_PAD ' ' +extern const char **environ; #else #define SETPROCTITLE_PAD '\0' #endif +static struct dhcpcd_ctx *setproctitle_ctx; static int setproctitle_argc; -static char *setproctitle_argv_last; +static const char *setproctitle_argv_last; static char **setproctitle_argv; static char *setproctitle_buf; int -setproctitle_init(int argc, char **argv) +setproctitle_init(struct dhcpcd_ctx *ctx, int argc, char **argv) { size_t i, len; char *p; + setproctitle_ctx = ctx; len = 0; for (i = 0; environ[i] != NULL; i++) len += strlen(environ[i]) + 1; @@ -119,16 +123,20 @@ setproctitle(const char *fmt, ...) int i; len = 0; - for (i = 0; i < setproctitle_argc; i++) - len += strlen(setproctitle_argv[i]) + 1; + for (i = 0; i < setproctitle_ctx->argc; i++) { + len += strlen(setproctitle_ctx->argv[i]) + 1; + } if (len > (size_t)(p - setproctitle_argv[0])) { p += strlcpy(p, " (", LAST_SIZE); for (i = 0; i < setproctitle_argc; i++) { - p += strlcpy(p, setproctitle_argv[i], LAST_SIZE); + p += strlcpy(p, setproctitle_ctx->argv[i], LAST_SIZE); p += strlcpy(p, " ", LAST_SIZE); } } + + if (*(p - 1) == ' ') + *(p - 1) = ')'; #endif if (setproctitle_argv_last - p > 0) diff --git a/compat/setproctitle.h b/compat/setproctitle.h index 18249947..ede12650 100644 --- a/compat/setproctitle.h +++ b/compat/setproctitle.h @@ -28,6 +28,8 @@ #ifndef SETPROCTITLE_H #define SETPROCTITLE_H +#include "dhcpcd.h" + #ifndef __printflike #if __GNUC__ > 2 || defined(__INTEL_COMPILER) #define __printflike(a, b) __attribute__((format(printf, a, b))) @@ -36,7 +38,7 @@ #endif #endif /* !__printflike */ -int setproctitle_init(int, char **); +int setproctitle_init(struct dhcpcd_ctx *ctx, int, char **); void setproctitle_free(void); __printflike(1, 2) void setproctitle(const char *, ...); #endif diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 85d9081f..0349b148 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -2026,7 +2026,7 @@ printpidfile: ctx.options |= DHCPCD_STARTED; #ifdef SETPROCTITLE_H - setproctitle_init(argc, argv); + setproctitle_init(&ctx, argc, argv); #endif setproctitle("%s%s%s", ctx.options & DHCPCD_MASTER ? "[master]" : argv[optind],