From c36c04537a232bc743ade21fc24ea0440febf38e Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Mon, 3 Apr 2017 10:24:52 +0200
Subject: [PATCH] integration fix: fixes for pthread_getname_np

- define _GNU_SOURCE before including pthread.h
- do not use static for the array 'threadname' used
  to store the name, it makes it a global variable
  accessed by several threads in parallel
- increase size of 'threadname' (maybe not necessary)
- properly indent #define / #under (# should be at column 1)
---
 openair2/UTIL/LOG/log.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/openair2/UTIL/LOG/log.c b/openair2/UTIL/LOG/log.c
index 26f3f852c10..9c28c4b68d0 100644
--- a/openair2/UTIL/LOG/log.c
+++ b/openair2/UTIL/LOG/log.c
@@ -28,6 +28,7 @@
 
 */
 
+#define _GNU_SOURCE  /* required for pthread_getname_np */
 //#define LOG_TEST 1
 
 #define COMPONENT_LOG
@@ -1033,8 +1034,8 @@ void logRecord_mt(const char *file, const char *func, int line, int comp,
     }
 
     if ( (g_log->flag & FLAG_THREAD) || (c->flag & FLAG_THREAD) ) {
-      #define THREAD_NAME_LEN 16
-      static char threadname[THREAD_NAME_LEN];
+#     define THREAD_NAME_LEN 128
+      char threadname[THREAD_NAME_LEN];
       if (pthread_getname_np(pthread_self(), threadname, THREAD_NAME_LEN) != 0)
       {
         perror("pthread_getname_np : ");
@@ -1042,7 +1043,7 @@ void logRecord_mt(const char *file, const char *func, int line, int comp,
         len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", threadname);
         if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
       }
-      #undef THREAD_NAME_LEN
+#     undef THREAD_NAME_LEN
     }
 
     if ( (g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT) ) {
-- 
GitLab