summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Lipponer <mail@sebastianlipponer.de>2021-09-14 08:45:11 +0200
committerGitHub <noreply@github.com>2021-09-14 15:45:11 +0900
commit8a1ec98b479b808f9801b98fa83d8de124490d64 (patch)
tree2c5b4f398d03d81ec4665c55d9b32538111e9e4c
parent4a82545662d7d9d9b54be7393c382a4d1759daef (diff)
downloadDLT-daemon-8a1ec98b479b808f9801b98fa83d8de124490d64.tar.gz
dlt_user: Use pthread_setname_np() if available (#326)
Use POSIX thread API to rename the housekeeper and segmented threads. The currently used prctl() function is Linux specific and in general not available on other platforms (e.g. QNX). Signed-off-by: Sebastian Lipponer <mail@sebastianlipponer.de>
-rw-r--r--cmake/CMakeLists.txt6
-rw-r--r--src/lib/dlt_user.c18
2 files changed, 19 insertions, 5 deletions
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 46b67e4..3ceae3c 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -90,6 +90,12 @@ else()
CHECK_FUNCTION_EXISTS( mq_receive HAVE_FUNC_MQRECEIVE)
endif()
+if(CMAKE_THREAD_LIBS_INIT)
+ CHECK_LIBRARY_EXISTS(${CMAKE_THREAD_LIBS_INIT} pthread_setname_np pthread.h HAVE_FUNC_PTHREAD_SETNAME_NP)
+else(CMAKE_THREAD_LIBS_INIT)
+ CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_FUNC_PTHREAD_SETNAME_NP)
+endif(CMAKE_THREAD_LIBS_INIT)
+
if(WITH_CHECK_CONFIG_FILE)
configure_file(${PROJECT_SOURCE_DIR}/cmake/config.h.cmake ${PROJECT_BINARY_DIR}/include/dlt/config.h)
endif(WITH_CHECK_CONFIG_FILE)
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index e3565af..3525ce9 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -47,7 +47,7 @@
#include <limits.h>
#ifdef linux
-# include <sys/prctl.h>
+# include <sys/prctl.h> /* for PR_SET_NAME */
#endif
#include <sys/types.h> /* needed for getpid() */
@@ -2949,8 +2949,12 @@ void dlt_user_trace_network_segmented_thread(void *unused)
{
/* Unused on purpose. */
(void)unused;
-#ifdef linux
- prctl(PR_SET_NAME, "dlt_segmented", 0, 0, 0);
+#ifdef DLT_USE_PTHREAD_SETNAME_NP
+ if (pthread_setname_np(dlt_user.dlt_segmented_nwt_handle, "dlt_segmented"))
+ dlt_log(LOG_WARNING, "Failed to rename segmented thread!\n");
+#elif linux
+ if (prctl(PR_SET_NAME, "dlt_segmented", 0, 0, 0) < 0)
+ dlt_log(LOG_WARNING, "Failed to rename segmented thread!\n");
#endif
pthread_cleanup_push(dlt_user_cleanup_handler, NULL);
@@ -3542,8 +3546,12 @@ void dlt_user_housekeeperthread_function(__attribute__((unused)) void *ptr)
}
#endif
-#ifdef linux
- prctl(PR_SET_NAME, "dlt_housekeeper", 0, 0, 0);
+#ifdef DLT_USE_PTHREAD_SETNAME_NP
+ if (pthread_setname_np(dlt_housekeeperthread_handle, "dlt_housekeeper"))
+ dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n");
+#elif linux
+ if (prctl(PR_SET_NAME, "dlt_housekeeper", 0, 0, 0) < 0)
+ dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n");
#endif
pthread_cleanup_push(dlt_user_cleanup_handler, NULL);