From: Fabian Grünbichler Date: Thu, 11 Apr 2024 12:00:53 +0000 (+0200) Subject: fix #5370: avoid duplicate hostname in syslog/journal X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=d6966ff8475022d5c6e421c73831c521e357cec1;p=debcargo-conf.git fix #5370: avoid duplicate hostname in syslog/journal Signed-off-by: Fabian Grünbichler --- diff --git a/src/syslog/debian/patches/fix-duplicate-hostname.patch b/src/syslog/debian/patches/fix-duplicate-hostname.patch new file mode 100644 index 000000000..a40583d87 --- /dev/null +++ b/src/syslog/debian/patches/fix-duplicate-hostname.patch @@ -0,0 +1,59 @@ +From eaa3940275e6977175754f35b44c3fc646779902 Mon Sep 17 00:00:00 2001 +From: Greg Kurz +Date: Sat, 13 Jan 2024 11:05:45 +0100 +Subject: [PATCH] Don't set hostname with the unix backend + +The UNIX socket specific initialization functions `init_unix()` and +`init_unix_custom()` take care of not setting the hostname in the +header. This is based on the assumption that a syslog relay will +set the appropriate hostname (see PR #7). + +The generic initialization function `init()` that supports UNIX, UDP +and TCP sockets does set the hostname unconditionally though. Users +of this API end up with an extra hostname being added to their logs, +as seen with virtiofsd for example : + +Jan 12 17:03:04 myhostname virtiofsd[70727]: myhostname virtiofsd[70725]: Waiting for vhost-user socket connection... + +Only set the hostname for UDP and TCP. + +Signed-off-by: Greg Kurz +--- + src/lib.rs | 16 +++++++++------- + 1 file changed, 9 insertions(+), 7 deletions(-) + +Index: syslog/src/lib.rs +=================================================================== +--- syslog.orig/src/lib.rs ++++ syslog/src/lib.rs +@@ -474,9 +474,9 @@ pub fn init( + ) -> Result<()> { + let (process_name, pid) = get_process_info()?; + let process = application_name.map(From::from).unwrap_or(process_name); +- let formatter = Formatter3164 { ++ let mut formatter = Formatter3164 { + facility, +- hostname: get_hostname().ok(), ++ hostname: None, + process, + pid, + }; +@@ -484,11 +484,13 @@ pub fn init( + let backend = unix(formatter.clone()) + .map(|logger: Logger| logger.backend) + .or_else(|_| { +- TcpStream::connect(("127.0.0.1", 601)).map(|s| LoggerBackend::Tcp(BufWriter::new(s))) +- }) +- .or_else(|_| { +- let udp_addr = "127.0.0.1:514".parse().unwrap(); +- UdpSocket::bind(("127.0.0.1", 0)).map(|s| LoggerBackend::Udp(s, udp_addr)) ++ formatter.hostname = get_hostname().ok(); ++ TcpStream::connect(("127.0.0.1", 601)) ++ .map(|s| LoggerBackend::Tcp(BufWriter::new(s))) ++ .or_else(|_| { ++ let udp_addr = "127.0.0.1:514".parse().unwrap(); ++ UdpSocket::bind(("127.0.0.1", 0)).map(|s| LoggerBackend::Udp(s, udp_addr)) ++ }) + })?; + log::set_boxed_logger(Box::new(BasicLogger::new(Logger { formatter, backend }))) + .chain_err(|| ErrorKind::Initialization)?; diff --git a/src/syslog/debian/patches/series b/src/syslog/debian/patches/series index fa7eaac47..f5ce5a57c 100644 --- a/src/syslog/debian/patches/series +++ b/src/syslog/debian/patches/series @@ -1 +1,2 @@ relax-deps.diff +fix-duplicate-hostname.patch