Skip to content

Commit 72bfa8f

Browse files
authored
journald: use argv0 for syslog identifier (#3372)
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 <[email protected]>
1 parent ac8c55f commit 72bfa8f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tracing-journald/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,16 @@ impl Layer {
100100
pub fn new() -> io::Result<Self> {
101101
#[cfg(unix)]
102102
{
103+
use std::path::Path;
104+
103105
let socket = UnixDatagram::unbound()?;
104106
let layer = Self {
105107
socket,
106108
field_prefix: Some("F".into()),
107-
syslog_identifier: std::env::current_exe()
108-
.ok()
109+
syslog_identifier: std::env::args_os()
110+
.next()
109111
.as_ref()
110-
.and_then(|p| p.file_name())
112+
.and_then(|p| Path::new(p).file_name())
111113
.map(|n| n.to_string_lossy().into_owned())
112114
// If we fail to get the name of the current executable fall back to an empty string.
113115
.unwrap_or_default(),

0 commit comments

Comments
 (0)