<p>pespin has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/22920">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">logging: gsmtap: Fill PID field for each message<br><br>It was recently discovered that PID field in gsmtap log messages was<br>always set to 0. Before this patch, the field was never being set.<br><br>The approach of this patch is to record the PID of the process once<br>during tgt creation, in order to avoid calling getpid() syscall on each<br>log line to be sent. The counterpart of this optimization is that<br>eventual fork() calls would still keep the old incorrect value, but I<br>think nobody can safely assume that fork() is possible once all this<br>kind of infrastructure has already been configured (fork() should only<br>be done really at the start of the program before any osmocom foo is<br>initialized).<br><br>Change-Id: I7db00d1810f0860166bffa0bda8566caa82e06a9<br>---<br>M include/osmocom/core/logging.h<br>M src/logging_gsmtap.c<br>2 files changed, 4 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/20/22920/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h</span><br><span>index c7f89de..c4068a0 100644</span><br><span>--- a/include/osmocom/core/logging.h</span><br><span>+++ b/include/osmocom/core/logging.h</span><br><span>@@ -314,6 +314,7 @@</span><br><span>                        struct gsmtap_inst *gsmtap_inst;</span><br><span>                     const char *ident;</span><br><span>                   const char *hostname;</span><br><span style="color: hsl(120, 100%, 40%);">+                 uint32_t pid;</span><br><span>                } tgt_gsmtap;</span><br><span> </span><br><span>            struct {</span><br><span>diff --git a/src/logging_gsmtap.c b/src/logging_gsmtap.c</span><br><span>index bd64271..9930419 100644</span><br><span>--- a/src/logging_gsmtap.c</span><br><span>+++ b/src/logging_gsmtap.c</span><br><span>@@ -38,6 +38,7 @@</span><br><span> #include <stdio.h></span><br><span> #include <string.h></span><br><span> #include <stdbool.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <unistd.h></span><br><span> </span><br><span> #ifdef HAVE_STRINGS_H</span><br><span> #include <strings.h></span><br><span>@@ -82,6 +83,7 @@</span><br><span>   /* Logging header */</span><br><span>         golh = (struct gsmtap_osmocore_log_hdr *) msgb_put(msg, sizeof(*golh));</span><br><span>      OSMO_STRLCPY_ARRAY(golh->proc_name, target->tgt_gsmtap.ident);</span><br><span style="color: hsl(120, 100%, 40%);">+  golh->pid = target->tgt_gsmtap.pid;</span><br><span>    if (subsys_name)</span><br><span>             OSMO_STRLCPY_ARRAY(golh->subsys, subsys_name + 1);</span><br><span>        else</span><br><span>@@ -148,6 +150,7 @@</span><br><span>   target->tgt_gsmtap.gsmtap_inst = gti;</span><br><span>     target->tgt_gsmtap.ident = talloc_strdup(target, ident);</span><br><span>  target->tgt_gsmtap.hostname = talloc_strdup(target, host);</span><br><span style="color: hsl(120, 100%, 40%);">+ target->tgt_gsmtap.pid = (uint32_t)getpid();</span><br><span> </span><br><span>  target->type = LOG_TGT_TYPE_GSMTAP;</span><br><span>       target->raw_output = _gsmtap_raw_output;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/22920">change 22920</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/libosmocore/+/22920"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I7db00d1810f0860166bffa0bda8566caa82e06a9 </div>
<div style="display:none"> Gerrit-Change-Number: 22920 </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>