procd: Don't use syslog before its initialization
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 12 Mar 2017 01:11:39 +0000 (02:11 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 20 Jun 2017 14:48:43 +0000 (16:48 +0200)
When procd starts a rcS script, it captures its stdout and stderr and
logs them via syslog(). The problem with that is that the rest of
procd code uses ulog rather than syslog() directly and ulog_open()
doesn't call openlog() immediately, but only after something is logged
with ulog(). This lazy calling of openlog() can result in the
following unwanted behavior:

1) When rcS's stdout/err is logged via syslog(), the log identifier is
   not set yet (due to openlog() not called) and so the log message
   lacks information about source.

2) procd can also log stdout/err from services. When a message from a
   service needs to be logged, ulog_open() is called to change the log
   identifier to match the service name/PID. After logging the service
   messages, ulog_open() is called again the change the identifier
   back to "procd". The lazy call to openlog() means that the messages
   logged directly with syslog() will be logged with the
   identification of the previously logged service and not of the rcS
   script that produced the message.

Both problems are fixed by replacing direct call to syslog() with
ULOG_NOTE, which automatically calls openlog() if needed.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
rcS.c

diff --git a/rcS.c b/rcS.c
index 0208a75ac76ac33a34d8f10f1978e5d9335a3e3e..48131462631b2c3ba7624195f722a032973eea0a 100644 (file)
--- a/rcS.c
+++ b/rcS.c
@@ -54,7 +54,7 @@ static void pipe_cb(struct ustream *s, int bytes)
                        break;
                *newline = 0;
                len = newline + 1 - str;
                        break;
                *newline = 0;
                len = newline + 1 - str;
-               syslog(LOG_NOTICE, "%s", str);
+               ULOG_NOTE("%s", str);
 #ifdef SHOW_BOOT_ON_CONSOLE
                fprintf(stderr, "%s\n", str);
 #endif
 #ifdef SHOW_BOOT_ON_CONSOLE
                fprintf(stderr, "%s\n", str);
 #endif