[ovs-dev] [PATCH 1/2] lib: Move addition of program_name to proctitle_set

Ed Maste emaste at adaranet.com
Thu Oct 11 20:49:38 UTC 2012


Signed-off-by: Ed Maste <emaste at adaranet.com>
---
 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 76a4e74..eb9f6b1 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 84ed614..71f6f81 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 bc44885..f2b896e 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);
--
1.7.11.5



More information about the dev mailing list