]> git.proxmox.com Git - debcargo-conf.git/commitdiff
fix #5370: avoid duplicate hostname in syslog/journal
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 11 Apr 2024 12:00:53 +0000 (14:00 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 11 Apr 2024 12:00:53 +0000 (14:00 +0200)
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/syslog/debian/patches/fix-duplicate-hostname.patch [new file with mode: 0644]
src/syslog/debian/patches/series

diff --git a/src/syslog/debian/patches/fix-duplicate-hostname.patch b/src/syslog/debian/patches/fix-duplicate-hostname.patch
new file mode 100644 (file)
index 0000000..a40583d
--- /dev/null
@@ -0,0 +1,59 @@
+From eaa3940275e6977175754f35b44c3fc646779902 Mon Sep 17 00:00:00 2001
+From: Greg Kurz <groug@kaod.org>
+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 <groug@kaod.org>
+---
+ 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<LoggerBackend, Formatter3164>| 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)?;
index fa7eaac47ad5a40677cea2b0cda0c7e773c51473..f5ce5a57cac13e1d9634e87a98485ca698d0d5a3 100644 (file)
@@ -1 +1,2 @@
 relax-deps.diff
+fix-duplicate-hostname.patch