diff --git a/sysklogd-1.4.1-systemd-multi.dif b/sysklogd-1.4.1-systemd-multi.dif new file mode 100644 index 0000000..4bf39d3 --- /dev/null +++ b/sysklogd-1.4.1-systemd-multi.dif @@ -0,0 +1,171 @@ +--- syslogd.c ++++ syslogd.c 2011/01/20 10:55:18 +@@ -574,6 +574,9 @@ static volatile sig_atomic_t restart; + int nfunix = 1; + char *funixn[MAXFUNIX] = { _PATH_LOG }; + int funix[MAXFUNIX] = { -1, }; ++#if defined(__linux__) ++int sd_fds = 0; ++#endif + + #ifdef UT_NAMESIZE + # define UNAMESZ UT_NAMESIZE /* length of a login name */ +@@ -1000,12 +1003,44 @@ int main(argc, argv) + exit(1); + } + ++ i = 0; + num_fds = getdtablesize(); + #if defined(__linux__) +- if (sd_listen_fds(0) <= 0) +-#endif +- for (i = 0; i < num_fds; i++) ++ /* if (sd_booted()) */ { ++ const char *e; ++ char buf[24] = { '\0' }; ++ char *p = NULL; ++ unsigned long l; ++ ++ /* fork & systemd socket activation: ++ * fetch listen pid and update to ours, ++ * when it is set to pid of our parent. ++ */ ++ if ( (e = getenv("LISTEN_PID"))) { ++ errno = 0; ++ l = strtoul(e, &p, 10); ++ if (errno == 0 && l > 0 && (!p || !*p)) { ++ if (getppid() == (pid_t)l) { ++ snprintf(buf, sizeof(buf), "%d", ++ getpid()); ++ setenv("LISTEN_PID", buf, 1); ++ } ++ } ++ } ++ ++ /* ++ * init sd_fds and close all fds, except ++ * of the fds provided by systemd. ++ */ ++ sd_fds = sd_listen_fds(0); ++ for( ; i < SD_LISTEN_FDS_START; i++) + (void) close(i); ++ if (sd_fds > 0) ++ i = SD_LISTEN_FDS_START + sd_fds; ++ } ++#endif ++ for ( ; i < num_fds; i++) ++ (void) close(i); + untty(); + break; + } +@@ -1041,7 +1076,12 @@ int main(argc, argv) + dprintf("Pidfile (and pid) already exist.\n"); + exit(1); + } +- } /* if ( !Debug ) */ ++ } /* if ( !(Debug || NoFork)) */ ++#if defined(__linux__) ++ /* if (sd_booted()) */ { ++ sd_fds = sd_listen_fds(0); ++ } ++#endif + } + #endif + +@@ -1323,54 +1363,30 @@ static int create_unix_socket(const char + 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"); ++ /* ++ * Check whether an FD was passed in from systemd. ++ * If so and it matches this socket, so use it. ++ */ ++ if (sd_fds < 0) { ++ logerror("Failed to acquire systemd socket"); + #ifndef SYSV +- dienow(); ++ dienow(); + #else +- return -1; ++ 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 (sd_fds > 0) { ++ for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + sd_fds; fd++) { ++ if( sd_is_socket_unix(fd, SOCK_DGRAM, -1, path, 0) == 1) { ++ /* ok, it matches -- just use as is */ ++ return fd; + } +- +- if (!r) { +- logerror("Passed systemd socket of wrong type"); +-#ifndef SYSV +- dienow(); +-#else +- return -1; +-#endif +- } +- +- return fd; ++ /* ++ * otherwise it either didn't matched *this* socket and ++ * we just continue to check the next one or there were ++ * an error and we will recreate it bellow. ++ */ + } + } + #endif +@@ -2485,14 +2501,17 @@ void dienow(void) + if (InetInuse) close(inetm); + + /* Clean-up files. */ +- i = 0; ++ for (i = 0; i < nfunix; i++) { ++ if (funixn[i] && funix[i] != -1) { + #if defined(__linux__) +- if (sd_listen_fds(0) > 0) +- i = 1; ++ if (sd_fds > 0 && ++ funix[i] >= SD_LISTEN_FDS_START && ++ funix[i] < SD_LISTEN_FDS_START + sd_fds) ++ continue; + #endif +- for (; i < nfunix; i++) +- if (funixn[i] && funix[i] != -1) + (void)unlink(funixn[i]); ++ } ++ } + + for (lognum = 0; lognum <= nlogs; lognum++) { + f = &Files[lognum]; diff --git a/syslogd.changes b/syslogd.changes index 6064576..3f20514 100644 --- a/syslogd.changes +++ b/syslogd.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Jan 20 09:37:15 UTC 2011 - mt@suse.de + +- Improved systemd socket activation support to support multiple + sockets and activation in forking mode (bnc#656104) + ------------------------------------------------------------------- Tue Nov 30 11:08:19 CET 2010 - werner@suse.de diff --git a/syslogd.spec b/syslogd.spec index 032b93d..0c5dc59 100644 --- a/syslogd.spec +++ b/syslogd.spec @@ -61,6 +61,7 @@ Patch21: sysklogd-1.4.1-nofortify.patch Patch22: sysklogd-1.4.1-sysmap-prior-to-2.5.patch Patch23: sysklogd-1.4.1-reload.dif Patch24: sysklogd-1.4.1-systemd.dif +Patch25: sysklogd-1.4.1-systemd-multi.dif BuildRoot: %{_tmppath}/%{name}-%{version}-build %description @@ -130,6 +131,7 @@ Authors: %patch22 -p0 -b .sysmap %patch23 -p0 -b .reload %patch24 -p0 -b .sd +%patch25 -p0 -b .sd2 %patch0 -p0 %build