configure.ac: Improve detection and usage of pthread_set_name_np(3).
authorFlorian Forster <octo@collectd.org>
Sat, 19 Nov 2016 07:10:47 +0000 (08:10 +0100)
committerFlorian Forster <octo@collectd.org>
Sat, 19 Nov 2016 07:10:47 +0000 (08:10 +0100)
configure.ac
src/daemon/plugin.c

index db17543..9c5df83 100644 (file)
@@ -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 <pthread.h>
-#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 <pthread.h>
-#endif
+#include <pthread_np.h>
 ]],
 [[
-        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
index 08c5199..ac9ce5b 100644 (file)
 #include "utils_time.h"
 #include "utils_random.h"
 
+#if HAVE_PTHREAD_NP_H
+# include <pthread_np.h> /* for pthread_set_name_np(3) */
+#endif
+
 #include <ltdl.h>
 
 /*
@@ -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);