util: Allow set_subprogram_name() to take a printf() format string.
[sliver-openvswitch.git] / lib / util.c
index b800455..a32c80a 100644 (file)
@@ -399,14 +399,26 @@ get_subprogram_name(void)
     return name ? name : "";
 }
 
-/* Sets 'name' as the name of the currently running thread or process.  (This
- * appears in log messages and may also be visible in system process listings
- * and debuggers.) */
+/* Sets the formatted value of 'format' as the name of the currently running
+ * thread or process.  (This appears in log messages and may also be visible in
+ * system process listings and debuggers.) */
 void
-set_subprogram_name(const char *name)
+set_subprogram_name(const char *format, ...)
 {
-    const char *pname = name[0] ? name : program_name;
-    free(subprogram_name_set(xstrdup(name)));
+    char *pname;
+
+    if (format) {
+        va_list args;
+
+        va_start(args, format);
+        pname = xvasprintf(format, args);
+        va_end(args);
+    } else {
+        pname = xstrdup(program_name);
+    }
+
+    free(subprogram_name_set(pname));
+
 #if HAVE_GLIBC_PTHREAD_SETNAME_NP
     pthread_setname_np(pthread_self(), pname);
 #elif HAVE_NETBSD_PTHREAD_SETNAME_NP