laforge has submitted this change. (
https://gerrit.osmocom.org/c/libosmocore/+/22920 )
Change subject: logging: gsmtap: Fill PID field for each message
......................................................................
logging: gsmtap: Fill PID field for each message
It was recently discovered that PID field in gsmtap log messages was
always set to 0. Before this patch, the field was never being set.
The approach of this patch is to record the PID of process one, in
order to avoid calling getpid() syscall on each
log line to be sent. The counterpart of this optimization is that
eventual fork() calls would still keep the old incorrect value, but I
think nobody can safely assume that fork() is possible once all this
kind of infrastructure has already been configured (fork() should only
be done really at the start of the program before any osmocom foo is
initialized, or to immediatelly call exec()).
Related: OS#5027
Change-Id: I7db00d1810f0860166bffa0bda8566caa82e06a9
---
M src/logging_gsmtap.c
1 file changed, 7 insertions(+), 0 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/src/logging_gsmtap.c b/src/logging_gsmtap.c
index bd64271..8947c5d 100644
--- a/src/logging_gsmtap.c
+++ b/src/logging_gsmtap.c
@@ -38,6 +38,7 @@
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
+#include <unistd.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
@@ -53,6 +54,8 @@
#define GSMTAP_LOG_MAX_SIZE 4096
+static uint32_t logging_gsmtap_pid;
+
static void _gsmtap_raw_output(struct log_target *target, int subsys,
unsigned int level, const char *file,
int line, int cont, const char *format,
@@ -82,6 +85,7 @@
/* Logging header */
golh = (struct gsmtap_osmocore_log_hdr *) msgb_put(msg, sizeof(*golh));
OSMO_STRLCPY_ARRAY(golh->proc_name, target->tgt_gsmtap.ident);
+ golh->pid = logging_gsmtap_pid;
if (subsys_name)
OSMO_STRLCPY_ARRAY(golh->subsys, subsys_name + 1);
else
@@ -152,6 +156,9 @@
target->type = LOG_TGT_TYPE_GSMTAP;
target->raw_output = _gsmtap_raw_output;
+ if (!logging_gsmtap_pid)
+ logging_gsmtap_pid = (uint32_t)getpid();
+
return target;
}
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22920
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I7db00d1810f0860166bffa0bda8566caa82e06a9
Gerrit-Change-Number: 22920
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-MessageType: merged