Add support for musl libc
Based on patch by mauropasse (issue #383). Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
		
							parent
							
								
									59d4d1eb57
								
							
						
					
					
						commit
						3de040d21a
					
				
					 2 changed files with 6 additions and 4 deletions
				
			
		| 
						 | 
					@ -18,7 +18,7 @@
 | 
				
			||||||
#include "dds/ddsi/q_log.h"
 | 
					#include "dds/ddsi/q_log.h"
 | 
				
			||||||
#include "dds/ddsi/sysdeps.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)
 | 
					void log_stacktrace (const struct ddsrt_log_cfg *logcfg, const char *name, ddsrt_thread_t tid)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  DDSRT_UNUSED_ARG (name);
 | 
					  DDSRT_UNUSED_ARG (name);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,6 +39,7 @@ typedef struct {
 | 
				
			||||||
} thread_context_t;
 | 
					} thread_context_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__linux)
 | 
					#if defined(__linux)
 | 
				
			||||||
 | 
					#include <sys/prctl.h>
 | 
				
			||||||
#include <sys/syscall.h>
 | 
					#include <sys/syscall.h>
 | 
				
			||||||
#include <dirent.h>
 | 
					#include <dirent.h>
 | 
				
			||||||
#define MAXTHREADNAMESIZE (15) /* 16 bytes including null-terminating byte. */
 | 
					#define MAXTHREADNAMESIZE (15) /* 16 bytes including null-terminating byte. */
 | 
				
			||||||
| 
						 | 
					@ -72,9 +73,10 @@ ddsrt_thread_getname(char *str, size_t size)
 | 
				
			||||||
  assert(size > 0);
 | 
					  assert(size > 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__linux)
 | 
					#if defined(__linux)
 | 
				
			||||||
  /* Thread names are limited to 16 bytes on Linux. ERANGE is returned if the
 | 
					  /* Thread names are limited to 16 bytes on Linux, which the buffer should
 | 
				
			||||||
     buffer is smaller than 16 bytes. Use an intermediate buffer. */
 | 
					     allow space for. prctl is favored over pthread_getname_np for
 | 
				
			||||||
  (void)pthread_getname_np(pthread_self(), buf, sizeof(buf));
 | 
					     portability. e.g. musl libc. */
 | 
				
			||||||
 | 
					  (void)prctl(PR_GET_NAME, (unsigned long)buf, 0UL, 0UL, 0UL);
 | 
				
			||||||
  cnt = ddsrt_strlcpy(str, buf, size);
 | 
					  cnt = ddsrt_strlcpy(str, buf, size);
 | 
				
			||||||
#elif defined(__APPLE__)
 | 
					#elif defined(__APPLE__)
 | 
				
			||||||
  /* pthread_getname_np on APPLE uses strlcpy to copy the thread name, but
 | 
					  /* pthread_getname_np on APPLE uses strlcpy to copy the thread name, but
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue