X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Futil.c;h=b8004555f6a2ff79533b23094b8102fcd9a4c29f;hb=ff14eb7ac9569ae09f7dc6672667cff907b35fc6;hp=c69d7d1509d95d8b9eb1bf1996908536ab6b99ed;hpb=bc9fb3a9cd588148e97eaae4eaa200faf0ac8d33;p=sliver-openvswitch.git diff --git a/lib/util.c b/lib/util.c index c69d7d150..b8004555f 100644 --- a/lib/util.c +++ b/lib/util.c @@ -30,6 +30,9 @@ #include "coverage.h" #include "ovs-thread.h" #include "vlog.h" +#ifdef HAVE_PTHREAD_SET_NAME_NP +#include +#endif VLOG_DEFINE_THIS_MODULE(util); @@ -46,7 +49,9 @@ DEFINE_PER_THREAD_MALLOCED_DATA(char *, subprogram_name); 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, @@ -395,11 +400,20 @@ get_subprogram_name(void) } /* Sets 'name' as the name of the currently running thread or process. (This - * appears in log messages.) */ + * appears in log messages and may also be visible in system process listings + * and debuggers.) */ void set_subprogram_name(const char *name) { + const char *pname = name[0] ? name : program_name; free(subprogram_name_set(xstrdup(name))); +#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(), pname); +#endif } /* Returns a pointer to a string describing the program version. The