From ee05a1b086cf0613b340da9d977658e309981ea3 Mon Sep 17 00:00:00 2001 From: Garrett Wollman Date: Fri, 8 Jul 2011 00:09:43 -0400 Subject: [PATCH] viced: If platform supports setting a thread title, do so Some pthread libraries support setting a name or title for individual threads (analogous to setproctitle() for processes). This can be useful for debugging and is sometimes published for use by utilities like ps (again like setproctitle() for processes). The two most common variants of this have the same signature with slightly different function names. If either one is present, use it in viced (which already assigns a thread name when compiled for LWP but ignores it in pthreads compilations). Change-Id: I5486aa6a21dbc3c8885b94ad52c2b1a66baae81f Reviewed-on: http://gerrit.openafs.org/4950 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- acinclude.m4 | 10 ++++++++++ src/viced/viced.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/acinclude.m4 b/acinclude.m4 index 850925341..41a001987 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1258,6 +1258,7 @@ AC_CHECK_HEADERS([ \ ncurses.h \ netdb.h \ netinet/in.h \ + pthread_np.h \ pwd.h \ regex.h \ resolv.h \ @@ -1553,6 +1554,15 @@ else AC_MSG_RESULT(no) fi +dnl Look for "non-portable" pthreads functions. +save_LIBS="$LIBS" +LIBS="$LIBS $PTHREAD_LIBS" +AC_CHECK_FUNCS([ \ + pthread_set_name_np \ + pthread_setname_np \ +]) +LIBS="$save_LIBS" + AC_TYPE_SIGNAL OPENAFS_RETSIGTYPE AC_CHECK_SIZEOF(void *) diff --git a/src/viced/viced.c b/src/viced/viced.c index 3aaa62133..d107244e2 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -75,6 +75,9 @@ #include "host.h" #ifdef AFS_PTHREAD_ENV # include +# ifdef HAVE_PTHREAD_NP_H +# include +# endif /* HAVE_PTHREAD_NP_H */ #endif #if defined(AFS_SGI_ENV) # include "sys/schedctl.h" @@ -416,6 +419,14 @@ setThreadId(char *s) /* set our 'thread-id' so that the host hold table works */ pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)rx_NewThreadId()); +# if defined(HAVE_PTHREAD_SET_NAME_NP) + /* The "NP" stands for "non-portable" so it's only just that + * implementations disagree about the name of the function. + */ + pthread_set_name_np(pthread_self(), s); +# elif defined(HAVE_PTHREAD_SETNAME_NP) + pthread_setname_np(pthread_self(), s); +# endif ViceLog(0, ("Set thread id %p for '%s'\n", pthread_getspecific(rx_thread_id_key), s)); -- 2.39.5