syslogd/sysklogd-1.4.1-systemd.dif

124 lines
2.9 KiB
Plaintext

---
Makefile | 4 +--
syslogd.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 67 insertions(+), 5 deletions(-)
--- Makefile
+++ Makefile 2022-10-17 09:00:32.945828594 +0000
@@ -20,7 +20,7 @@
CC= gcc
#SKFLAGS= -g -DSYSV -Wall
#LDFLAGS= -g
-SKFLAGS= $(RPM_OPT_FLAGS) -DINET6 -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce
+SKFLAGS= $(RPM_OPT_FLAGS) -DINET6 -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce -I.
# -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
# -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
# $(shell getconf LFS_SKFLAGS)
@@ -43,7 +43,7 @@ MANDIR = $(prefix)/usr/share/man
# specific to the ALPHA. If you are attempting to build this package under
# an ALPHA and linking fails with unresolved references please try
# uncommenting the following define.
-# LIBS = ${LIBS} -linux
+LIBS += $(shell pkg-config libsystemd --libs)
# Define the following to impart start-up delay in klogd. This is
# useful if klogd is started simultaneously or in close-proximity to syslogd.
--- syslogd.c
+++ syslogd.c 2022-10-17 08:59:33.354879789 +0000
@@ -558,6 +558,7 @@ static char sccsid[] __attribute__ ((un
#if defined(__linux__)
#include <paths.h>
+#include <systemd/sd-daemon.h>
#endif
#ifndef UTMP_FILE
@@ -1047,8 +1048,11 @@ int main(argc, argv)
}
num_fds = getdtablesize();
- for (i = 0; i < num_fds; i++)
- (void) close(i);
+#if defined(__linux__)
+ if (sd_listen_fds(0) <= 0)
+#endif
+ for (i = 0; i < num_fds; i++)
+ (void) close(i);
untty();
break;
}
@@ -1362,6 +1366,59 @@ static int create_unix_socket(const char
if (path[0] == '\0')
return -1;
+#if defined(__linux__)
+ if (strcmp(path, _PATH_LOG) == 0) {
+ int r;
+
+ /* Check whether an FD was passed in from systemd. If
+ * so, it's the /dev/log socket, so use it. */
+
+ r = sd_listen_fds(0);
+ if (r < 0) {
+ logerror("Failed to acquire systemd socket");
+#ifndef SYSV
+ dienow();
+#else
+ return -1;
+#endif
+ }
+
+
+ if (r > 1) {
+ logerror("Wrong number of systemd sockets passed");
+#ifndef SYSV
+ dienow();
+#else
+ return -1;
+#endif
+ }
+
+ if (r == 1) {
+ fd = SD_LISTEN_FDS_START;
+ r = sd_is_socket_unix(fd, SOCK_DGRAM, -1, _PATH_LOG, 0);
+ if (r < 0) {
+ logerror("Failed to verify systemd socket type");
+#ifndef SYSV
+ dienow();
+#else
+ return -1;
+#endif
+ }
+
+ if (!r) {
+ logerror("Passed systemd socket of wrong type");
+#ifndef SYSV
+ dienow();
+#else
+ return -1;
+#endif
+ }
+
+ return fd;
+ }
+ }
+#endif
+
(void) unlink(path);
memset(&sunx, 0, sizeof(sunx));
@@ -2480,7 +2537,12 @@ void dienow(void)
if (InetInuse) close(inetm);
/* Clean-up files. */
- for (i = 0; i < nfunix; i++)
+ i = 0;
+#if defined(__linux__)
+ if (sd_listen_fds(0) > 0)
+ i = 1;
+#endif
+ for (; i < nfunix; i++)
if (funixn[i] && funix[i] != -1)
(void)unlink(funixn[i]);