diff mbox series

[1/1] log: Use a log identity always valid while logging

Message ID 20240222232326.1677146-2-christian.meusel@posteo.de (mailing list archive)
State Accepted
Commit 8bd6504f449f368b008b68cd37521817d6d8bf5a
Headers show
Series Use a log identity always valid while logging | expand

Commit Message

Christian Meusel Feb. 22, 2024, 11:23 p.m. UTC
The result from basename is not guaranteed to be.

I'm running connmand 1.42 on Yocto Kirkstone and in this setup log
identities ending up in the journal are garbage and change during the
run of a connmand process.

Explicitly allocating the log identity fixes this behaviour and gives
the expected 'connmand'.
---
 src/log.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/log.c b/src/log.c
index f7483194..108dcb0b 100644
--- a/src/log.c
+++ b/src/log.c
@@ -36,6 +36,11 @@ 
 
 static const char *program_exec;
 static const char *program_path;
+/*
+ * Provide a log identy to syslog whose lifetime is greater than the timespan
+ * we're logging. The result from basename does not guarantee that.
+ */
+static char *syslog_identity;
 
 /* This makes sure we always have a __debug section. */
 CONNMAN_DEBUG_ALIAS(dummy);
@@ -212,7 +217,11 @@  int __connman_log_init(const char *program, const char *debug,
 	if (backtrace)
 		signal_setup(signal_handler);
 
-	openlog(basename(program), option, LOG_DAEMON);
+	/* Clean up any previos identity and set the new one. */
+	g_free(syslog_identity);
+	syslog_identity = g_path_get_basename(program);
+
+	openlog(syslog_identity, option, LOG_DAEMON);
 
 	syslog(LOG_INFO, "%s version %s", program_name, program_version);
 
@@ -228,5 +237,8 @@  void __connman_log_cleanup(gboolean backtrace)
 	if (backtrace)
 		signal_setup(SIG_DFL);
 
+	g_free(syslog_identity);
+	syslog_identity = NULL;
+
 	g_strfreev(enabled);
 }