From 74dddefcc76f15540c628af45eae3d8bc58dc452 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 17 Feb 2021 18:55:44 +0100 Subject: [PATCH] logging: gsmtap: Store TID instead of PID in pkt hdr This allows differentiating threads withing an application, while still keeping same numbering for single-threaded application (since first thread ID is always the same as the process group ID). Related: OS#5027 Change-Id: I33da02524fc064e133b2b762af7060139c4cfd81 --- src/logging_gsmtap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/logging_gsmtap.c b/src/logging_gsmtap.c index 052460231..e190f88fd 100644 --- a/src/logging_gsmtap.c +++ b/src/logging_gsmtap.c @@ -51,10 +51,11 @@ #include #include #include +#include #define GSMTAP_LOG_MAX_SIZE 4096 -static uint32_t logging_gsmtap_pid; +static __thread uint32_t logging_gsmtap_tid; static void _gsmtap_raw_output(struct log_target *target, int subsys, unsigned int level, const char *file, @@ -85,7 +86,9 @@ static void _gsmtap_raw_output(struct log_target *target, int subsys, /* 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 (logging_gsmtap_tid == 0) + osmo_store32be((uint32_t)osmo_gettid(), &logging_gsmtap_tid); + golh->pid = logging_gsmtap_tid; if (subsys_name) OSMO_STRLCPY_ARRAY(golh->subsys, subsys_name + 1); else @@ -156,9 +159,6 @@ struct log_target *log_target_create_gsmtap(const char *host, uint16_t port, target->type = LOG_TGT_TYPE_GSMTAP; target->raw_output = _gsmtap_raw_output; - if (!logging_gsmtap_pid) - osmo_store32be((uint32_t)getpid(), &logging_gsmtap_pid); - return target; }