File: syslogd-make-it-optionally-systemd-socket-activated.patch

package info (click to toggle)
busybox 1%3A1.37.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,684 kB
  • sloc: ansic: 190,169; sh: 10,414; cpp: 1,428; makefile: 1,005; asm: 798; yacc: 570; lex: 355; perl: 334; python: 112; awk: 29
file content (33 lines) | stat: -rw-r--r-- 1,152 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
From: Michael Tokarev <mjt@tls.msk.ru>
Date: Thu, 16 Nov 2023 09:39:33 +0300
Subject: syslogd: make it optionally systemd-socket-activated
Forwarded: no

In order for busybox-syslogd to work with systemd, it needs to be
socket-activated: https://www.freedesktop.org/wiki/Software/systemd/syslog.
This patch implements very basic of sd_listen_fds(3) for syslogd context.
We only check for single LISTEN_FD and require it to be AF_LINUX socket.

diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 6ddfd771a..b7d0fbe6b 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -964,6 +964,18 @@ static NOINLINE int create_socket(void)
 	int sock_fd;
 	char *dev_log_name;
 
+	/* check for systemd socket-activated run from /run/systemd/journal/syslog
+	 * See https://www.freedesktop.org/wiki/Software/systemd/syslog/
+	 * We only support 1 filedescriptor here.
+	 * Checking for $LISTEN_FDS is probably unnecessary.
+	 */
+	socklen_t sunxl = sizeof(sunx);
+	if (getenv("LISTEN_FDS") &&
+		getsockname(3, &sunx, &sunxl) == 0 &&
+		sunx.sun_family == AF_UNIX) {
+		return 3;
+	}
+
 	memset(&sunx, 0, sizeof(sunx));
 	sunx.sun_family = AF_UNIX;