<p>pespin has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-trx/+/17226">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">debug.h: Avoid printing pthread_t type<br><br>Using %lu for pthread_t was wrong on armv7l arch. Even worse, according<br>to pthread_self() man page, pthread_t cannot be assumed to be of a simple<br>type and hence printable:<br>"""<br>POSIX.1 allows an implementation wide freedom in choosing the type used<br>to represent a thread ID; for example, representation using either an<br>arithmetic  type  or a structure is permitted.<br>"""<br><br>Let's use gettid() instead. According to glibc documentation:<br>"""<br>The pid_t data type is a signed integer type which is capable of<br>representing a process ID. In the GNU C Library, this is an int.<br>"""<br>It may not be the same on other libc's though, so let's better cast to a<br>long int just in case.<br><br>Accordign to gettid() man, the libc function was only added recently<br>during glibc 2.30, however the system call has been around for quite<br>some time (linux 2.4.11). Let's accomodate use udner non-glibc or older<br>versions of it by having a direct syscall fallback.<br><br>Change-Id: I40265fd4c62e550014ba3ff3335ca053c5bc01f2<br>---<br>M CommonLibs/debug.c<br>M CommonLibs/debug.h<br>M configure.ac<br>3 files changed, 37 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/26/17226/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/CommonLibs/debug.c b/CommonLibs/debug.c</span><br><span>index c227435..5e09079 100644</span><br><span>--- a/CommonLibs/debug.c</span><br><span>+++ b/CommonLibs/debug.c</span><br><span>@@ -21,7 +21,17 @@</span><br><span>  * See the COPYING file in the main directory for details.</span><br><span>  */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#include <pthread.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include "config.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* If HAVE_GETTID, then "_GNU_SOURCE" may need to be defined to use gettid() */</span><br><span style="color: hsl(120, 100%, 40%);">+#if HAVE_GETTID</span><br><span style="color: hsl(120, 100%, 40%);">+#define _GNU_SOURCE</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <sys/types.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <unistd.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <sys/syscall.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include "config.h"</span><br><span> </span><br><span> #include <osmocom/core/logging.h></span><br><span> #include <osmocom/core/utils.h></span><br><span>@@ -77,3 +87,15 @@</span><br><span>       .cat = default_categories,</span><br><span>   .num_cat = ARRAY_SIZE(default_categories),</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+pid_t my_gettid(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+#if HAVE_GETTID</span><br><span style="color: hsl(120, 100%, 40%);">+ return gettid();</span><br><span style="color: hsl(120, 100%, 40%);">+#elif defined(LINUX) && defined(__NR_gettid)</span><br><span style="color: hsl(120, 100%, 40%);">+        return (pid_t) syscall(__NR_gettid);</span><br><span style="color: hsl(120, 100%, 40%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+   #pragma message ("use pid as tid")</span><br><span style="color: hsl(120, 100%, 40%);">+  return getpid();</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/CommonLibs/debug.h b/CommonLibs/debug.h</span><br><span>index 0dca2ee..9f118b5 100644</span><br><span>--- a/CommonLibs/debug.h</span><br><span>+++ b/CommonLibs/debug.h</span><br><span>@@ -1,7 +1,7 @@</span><br><span> #pragma once</span><br><span> </span><br><span> #include <stdbool.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <pthread.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <sys/types.h></span><br><span> </span><br><span> #include <osmocom/core/logging.h></span><br><span> </span><br><span>@@ -18,10 +18,12 @@</span><br><span>        DDEVDRV,</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+pid_t my_gettid(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #define CLOGC(category, level, fmt, args...) do { \</span><br><span style="color: hsl(0, 100%, 40%);">-     LOGP(category, level, "[tid=%lu] " fmt, pthread_self(), ##args);  \</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(category, level, "[tid=%ld] " fmt, (long int) my_gettid(), ##args);  \</span><br><span> } while(0)</span><br><span> </span><br><span> #define CLOGCHAN(chan, category, level, fmt, args...) do { \</span><br><span style="color: hsl(0, 100%, 40%);">- LOGP(category, level, "[tid=%lu][chan=%lu] " fmt, pthread_self(), chan, ##args);  \</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(category, level, "[tid=%ld][chan=%lu] " fmt, (long int) my_gettid(), chan, ##args);  \</span><br><span> } while(0)</span><br><span>diff --git a/configure.ac b/configure.ac</span><br><span>index b0be728..76c3515 100644</span><br><span>--- a/configure.ac</span><br><span>+++ b/configure.ac</span><br><span>@@ -75,6 +75,15 @@</span><br><span> AC_HEADER_TIME</span><br><span> AC_C_BIGENDIAN</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+# Check if gettid is available (despite not being documented in glibc doc, it requires __USE_GNU on some systems)</span><br><span style="color: hsl(120, 100%, 40%);">+# C compiler is used since __USE_GNU seems to be always defined for g++.</span><br><span style="color: hsl(120, 100%, 40%);">+save_CPPFLAGS=$CPPFLAGS</span><br><span style="color: hsl(120, 100%, 40%);">+AC_LANG_PUSH(C)</span><br><span style="color: hsl(120, 100%, 40%);">+CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"</span><br><span style="color: hsl(120, 100%, 40%);">+AC_CHECK_FUNCS([gettid])</span><br><span style="color: hsl(120, 100%, 40%);">+AC_LANG_POP(C)</span><br><span style="color: hsl(120, 100%, 40%);">+CPPFLAGS=$save_CPPFLAGS</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.3.0)</span><br><span> PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.3.0)</span><br><span> PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.3.0)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-trx/+/17226">change 17226</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-trx/+/17226"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-trx </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I40265fd4c62e550014ba3ff3335ca053c5bc01f2 </div>
<div style="display:none"> Gerrit-Change-Number: 17226 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>