From: Florian Forster Date: Sat, 19 Nov 2016 07:10:47 +0000 (+0100) Subject: configure.ac: Improve detection and usage of pthread_set_name_np(3). X-Git-Tag: collectd-5.7.0~32^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0dc6fd79c3f33d7337f01bf5fefd48a7e48f67c2;p=collectd.git configure.ac: Improve detection and usage of pthread_set_name_np(3). --- diff --git a/configure.ac b/configure.ac index db175434..9c5df839 100644 --- a/configure.ac +++ b/configure.ac @@ -214,7 +214,7 @@ AC_HEADER_SYS_WAIT AC_HEADER_DIRENT AC_HEADER_STDBOOL -AC_CHECK_HEADERS(stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h sys/isa_defs.h fnmatch.h libgen.h) +AC_CHECK_HEADERS(stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h sys/isa_defs.h fnmatch.h libgen.h pthread_np.h) # For entropy plugin on newer NetBSD AC_CHECK_HEADERS(sys/rndio.h, [], [], @@ -1663,46 +1663,43 @@ AC_CHECK_MEMBERS([kstat_io_t.nwritten, kstat_io_t.writes, kstat_io_t.nwrites, ks ]) # check for pthread_setname_np -SAVE_LDFLAGS=$LDFLAGS +SAVE_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -lpthread" AC_MSG_CHECKING([if have pthread_setname_np]) have_pthread_setname_np="no" AC_LINK_IFELSE([AC_LANG_PROGRAM( [[ -#if HAVE_PTHREAD_H +#define _GNU_SOURCE #include -#endif ]], [[ - pthread_setname_np(pthread_self(), "conftest"); + pthread_setname_np((pthread_t) {0}, "conftest"); ]] )], [ have_pthread_setname_np="yes" - AC_DEFINE(HAVE_PTHREAD_SETNAME_NP, 1, [ pthread_setname_np() is available.]) + AC_DEFINE(HAVE_PTHREAD_SETNAME_NP, 1, [pthread_setname_np() is available.]) ]) -AC_MSG_RESULT([$have_pthread_set_name_np]) +AC_MSG_RESULT([$have_pthread_setname_np]) -# check for pthread_set_name_np +# check for pthread_set_name_np(3) (FreeBSD) AC_MSG_CHECKING([if have pthread_set_name_np]) have_pthread_set_name_np="no" AC_LINK_IFELSE([AC_LANG_PROGRAM( [[ -#if HAVE_PTHREAD_H -#include -#endif +#include ]], [[ - pthread_set_name_np(pthread_self(), "conftest"); + pthread_set_name_np((pthread_t) {0}, "conftest"); ]] )], [ have_pthread_set_name_np="yes" - AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP, 1, [ pthread_set_name_np() is available.]) + AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP, 1, [pthread_set_name_np() is available.]) ]) AC_MSG_RESULT([$have_pthread_set_name_np]) -LDFLAGS=$SAVE_LDFLAGS +LDFLAGS="$SAVE_LDFLAGS" # # Checks for libraries begin here diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 08c51995..ac9ce5bd 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -42,6 +42,10 @@ #include "utils_time.h" #include "utils_random.h" +#if HAVE_PTHREAD_NP_H +# include /* for pthread_set_name_np(3) */ +#endif + #include /* @@ -666,8 +670,9 @@ static void start_read_threads (int num) plugin_read_thread, NULL) == 0) { #if defined(HAVE_PTHREAD_SETNAME_NP) || defined(HAVE_PTHREAD_SET_NAME_NP) - char thread_name[16]; - sstrncpy (thread_name, "plugin reader", sizeof(thread_name)); + char thread_name[32]; + ssnprintf(thread_name, sizeof (thread_name), + "plugin reader#%d", i); # if defined(HAVE_PTHREAD_SETNAME_NP) pthread_setname_np (*(read_threads + read_threads_num), thread_name);