From d86a6c099ff4a1e0c7d1b437fa4ff0a9684fcdb9 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 11 Oct 2012 20:49:38 +0000 Subject: [PATCH] lib: Move addition of program_name to proctitle_set Signed-off-by: Ed Maste Signed-off-by: Ben Pfaff --- lib/command-line.c | 9 ++++++--- lib/daemon.c | 5 ++--- lib/worker.c | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/command-line.c b/lib/command-line.c index 76a4e748..07935d6a 100644 --- a/lib/command-line.c +++ b/lib/command-line.c @@ -140,8 +140,8 @@ proctitle_init(int argc, char **argv) } } -/* Changes the name of the process, as shown by "ps", to 'format', which is - * formatted as if by printf(). */ +/* Changes the name of the process, as shown by "ps", to the program name + * followed by 'format', which is formatted as if by printf(). */ void proctitle_set(const char *format, ...) { @@ -157,7 +157,10 @@ proctitle_set(const char *format, ...) } va_start(args, format); - n = vsnprintf(argv_start, argv_size, format, args); + n = snprintf(argv_start, argv_size, "%s: ", program_name); + if (n < argv_size) { + n += vsnprintf(argv_start + n, argv_size - n, format, args); + } if (n >= argv_size) { /* The name is too long, so add an ellipsis at the end. */ strcpy(&argv_start[argv_size - 4], "..."); diff --git a/lib/daemon.c b/lib/daemon.c index 84ed6147..71f6f811 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -385,9 +385,8 @@ monitor_daemon(pid_t daemon_pid) int retval; int status; - proctitle_set("%s: monitoring pid %lu (%s)", - program_name, (unsigned long int) daemon_pid, - status_msg); + proctitle_set("monitoring pid %lu (%s)", + (unsigned long int) daemon_pid, status_msg); do { retval = waitpid(daemon_pid, &status, 0); diff --git a/lib/worker.c b/lib/worker.c index bc448855..f2b896e8 100644 --- a/lib/worker.c +++ b/lib/worker.c @@ -335,8 +335,7 @@ worker_main(int fd) server_sock = fd; subprogram_name = "worker"; - proctitle_set("%s: worker process for pid %lu", - program_name, (unsigned long int) getppid()); + proctitle_set("worker process for pid %lu", (unsigned long int) getppid()); VLOG_INFO("worker process started"); rxbuf_init(&rx); -- 2.30.2