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;
|