From 4aeafa44699c531ce972ad218d5eb9463439a59f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 5 Sep 2025 10:33:31 -0400 Subject: [PATCH] journald: use argv0 for syslog identifier The libsystemd code is documented to determine the syslog identifier by using https://man7.org/linux/man-pages/man3/program_invocation_short_name.3.html (a glibc thing). This code is parsing via looking at `/proc/self/exe`. Often, these things are the same, but in my case they're not because for unfortunate reasons I need to re-exec the current binary in a tempfile. It's actually simpler and more reliable for us anyways to match what libsystemd is doing by looking at argv[0]. Signed-off-by: Colin Walters --- tracing-journald/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tracing-journald/src/lib.rs b/tracing-journald/src/lib.rs index fc794788f..5b6ae6ee6 100644 --- a/tracing-journald/src/lib.rs +++ b/tracing-journald/src/lib.rs @@ -100,14 +100,16 @@ impl Layer { pub fn new() -> io::Result { #[cfg(unix)] { + use std::path::Path; + let socket = UnixDatagram::unbound()?; let layer = Self { socket, field_prefix: Some("F".into()), - syslog_identifier: std::env::current_exe() - .ok() + syslog_identifier: std::env::args_os() + .next() .as_ref() - .and_then(|p| p.file_name()) + .and_then(|p| Path::new(p).file_name()) .map(|n| n.to_string_lossy().into_owned()) // If we fail to get the name of the current executable fall back to an empty string. .unwrap_or_default(),