From 3de040d21ad7bac1e6d55779219b2f50675236bd Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Wed, 5 Feb 2020 23:23:04 +0100 Subject: [PATCH] Add support for musl libc Based on patch by mauropasse (issue #383). Signed-off-by: Jeroen Koekkoek --- src/core/ddsi/src/sysdeps.c | 2 +- src/ddsrt/src/threads/posix/threads.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/ddsi/src/sysdeps.c b/src/core/ddsi/src/sysdeps.c index e7b2915..b1ce8c3 100644 --- a/src/core/ddsi/src/sysdeps.c +++ b/src/core/ddsi/src/sysdeps.c @@ -18,7 +18,7 @@ #include "dds/ddsi/q_log.h" #include "dds/ddsi/sysdeps.h" -#if DDSRT_WITH_FREERTOS || !(defined __APPLE__ || defined __linux) || (__GNUC__ > 0 && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40100) +#if DDSRT_WITH_FREERTOS || !(defined __APPLE__ || (defined __linux && (defined __GLIBC__ || defined __UCLIBC__))) || (__GNUC__ > 0 && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40100) void log_stacktrace (const struct ddsrt_log_cfg *logcfg, const char *name, ddsrt_thread_t tid) { DDSRT_UNUSED_ARG (name); diff --git a/src/ddsrt/src/threads/posix/threads.c b/src/ddsrt/src/threads/posix/threads.c index 0d2c387..14d09fd 100644 --- a/src/ddsrt/src/threads/posix/threads.c +++ b/src/ddsrt/src/threads/posix/threads.c @@ -39,6 +39,7 @@ typedef struct { } thread_context_t; #if defined(__linux) +#include #include #include #define MAXTHREADNAMESIZE (15) /* 16 bytes including null-terminating byte. */ @@ -72,9 +73,10 @@ ddsrt_thread_getname(char *str, size_t size) assert(size > 0); #if defined(__linux) - /* Thread names are limited to 16 bytes on Linux. ERANGE is returned if the - buffer is smaller than 16 bytes. Use an intermediate buffer. */ - (void)pthread_getname_np(pthread_self(), buf, sizeof(buf)); + /* Thread names are limited to 16 bytes on Linux, which the buffer should + allow space for. prctl is favored over pthread_getname_np for + portability. e.g. musl libc. */ + (void)prctl(PR_GET_NAME, (unsigned long)buf, 0UL, 0UL, 0UL); cnt = ddsrt_strlcpy(str, buf, size); #elif defined(__APPLE__) /* pthread_getname_np on APPLE uses strlcpy to copy the thread name, but