#include "coverage.h"
#include "ovs-thread.h"
#include "vlog.h"
+#ifdef HAVE_PTHREAD_SET_NAME_NP
+#include <pthread_np.h>
+#endif
VLOG_DEFINE_THIS_MODULE(util);
static char *program_version;
/* Buffer used by ovs_strerror(). */
-DEFINE_PER_THREAD_DATA(struct { char s[128]; }, strerror_buffer, { "" });
+DEFINE_STATIC_PER_THREAD_DATA(struct { char s[128]; },
+ strerror_buffer,
+ { "" });
void
ovs_assert_failure(const char *where, const char *function,
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, ...)
{
- free(subprogram_name_set(xstrdup(name)));
-#if HAVE_PTHREAD_SETNAME_NP
- pthread_setname_np(pthread_self(), 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
+ pthread_setname_np(pthread_self(), "%s", pname);
#elif HAVE_PTHREAD_SET_NAME_NP
- pthread_set_name_np(pthread_self(), name);
+ pthread_set_name_np(pthread_self(), pname);
#endif
}