diff options
| author | Roy Marples <roy@marples.name> | 2019-10-15 14:39:44 +0300 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2019-10-15 14:39:44 +0300 |
| commit | c085a2836f8439bc3e9d01a85d399afb8ad1dc12 (patch) | |
| tree | cf0159cd1aa5986413273f6d4787445d2affd617 /compat | |
| parent | cbcb352f10de5ba5185860f20e148509081f9d2f (diff) | |
| download | dhcpcd-c085a2836f8439bc3e9d01a85d399afb8ad1dc12.tar.xz | |
compat: Fix setproctitle on Solaris
Diffstat (limited to 'compat')
| -rw-r--r-- | compat/setproctitle.c | 18 | ||||
| -rw-r--r-- | compat/setproctitle.h | 4 |
2 files changed, 16 insertions, 6 deletions
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 <string.h> #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 |
