summaryrefslogtreecommitdiff
path: root/tools/syslogd.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2011-02-17 21:19:28 +0100
committerMichael Biebl <biebl@debian.org>2011-02-17 21:19:28 +0100
commit4d8f0c039c4fa44bb43d3cdbb0674cde8bb66de4 (patch)
treeed9a0691ad8b9ec5cabfe898c2a44dd4690fbe21 /tools/syslogd.c
parent537e74be114f1698f9ec825cf8ea497ffc0f17c5 (diff)
downloadrsyslog-4d8f0c039c4fa44bb43d3cdbb0674cde8bb66de4.tar.gz
Imported Upstream version 5.7.4upstream/5.7.4
Diffstat (limited to 'tools/syslogd.c')
-rw-r--r--tools/syslogd.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/tools/syslogd.c b/tools/syslogd.c
index 19a5900..c4a3b27 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -574,7 +574,7 @@ logmsgInternal(int iErr, int pri, uchar *msg, int flags)
}
if(bHaveMainQueue == 0) { /* not yet in queued mode */
- iminternalAddMsg(pri, pMsg);
+ iminternalAddMsg(pMsg);
} else {
/* we have the queue, so we can simply provide the
* message to the queue engine.
@@ -1868,10 +1868,9 @@ void sigttin_handler()
*/
static inline void processImInternal(void)
{
- int iPri;
msg_t *pMsg;
- while(iminternalRemoveMsg(&iPri, &pMsg) == RS_RET_OK) {
+ while(iminternalRemoveMsg(&pMsg) == RS_RET_OK) {
submitMsg(pMsg);
}
}
@@ -2429,13 +2428,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 sd_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 "