lib: Move addition of program_name to proctitle_set
authorEd Maste <emaste@adaranet.com>
Thu, 11 Oct 2012 20:49:38 +0000 (20:49 +0000)
committerBen Pfaff <blp@nicira.com>
Thu, 11 Oct 2012 21:02:00 +0000 (14:02 -0700)
Signed-off-by: Ed Maste <emaste@adaranet.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/command-line.c
lib/daemon.c
lib/worker.c

index 76a4e74..07935d6 100644 (file)
@@ -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], "...");
index 84ed614..71f6f81 100644 (file)
@@ -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);
index bc44885..f2b896e 100644 (file)
@@ -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);