summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMarius Tomaschewski <mt@suse.de>2011-02-11 09:24:45 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2011-02-11 11:13:46 +0100
commit1b84d5998926df6ef1b2bbfc9fe5a59a80c5564c (patch)
treef0dabf5eb503e5bc3862502af12ba471ac4c34fa /tools
parenta9736c6215cf6446c326b034648f63a79c0426f9 (diff)
downloadrsyslog-1b84d5998926df6ef1b2bbfc9fe5a59a80c5564c.tar.gz
rsyslog-1b84d5998926df6ef1b2bbfc9fe5a59a80c5564c.tar.xz
rsyslog-1b84d5998926df6ef1b2bbfc9fe5a59a80c5564c.zip
Improved systemd socket activation support
Support for multiple unix sockets and activation in forking mode Signed-off-by: Marius Tomaschewski <mt@suse.de>
Diffstat (limited to 'tools')
-rw-r--r--tools/syslogd.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/tools/syslogd.c b/tools/syslogd.c
index 19a5900c..52c0be5f 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -2429,13 +2429,46 @@ doGlblProcessInit(void)
*/
exit(1); /* "good" exit - after forking, not diasabling anything */
}
+
num_fds = getdtablesize();
close(0);
/* we keep stdout and stderr open in case we have to emit something */
+ i = 3;
+
+ /* if (sd_booted()) */ {
+ const char *e;
+ char buf[24] = { '\0' };
+ char *p = NULL;
+ unsigned long l;
+ int fds;
+
+ /* 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);
+ }
+ }
+ }
+
+ /*
+ * close only all further fds, except
+ * of the fds provided by systemd.
+ */
+ sd_fds = sd_listen_fds(0);
+ if (sd_fds > 0)
+ i = SD_LISTEN_FDS_START + sd_fds;
+ }
+ for ( ; i < num_fds; i++)
+ (void) close(i);
- if (sd_listen_fds(0) <= 0)
- for (i = 3; i < num_fds; i++)
- (void) close(i);
untty();
} else {
fputs(" Already running. If you want to run multiple instances, you need "