[LEDE-DEV] [PATCH v2] procd: Don't use syslog before its initialization

Michal Sojka sojkam1 at fel.cvut.cz
Sat Mar 11 17:11:39 PST 2017


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 at fel.cvut.cz>
---
 rcS.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rcS.c b/rcS.c
index 0208a75..4813146 100644
--- 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;
-		syslog(LOG_NOTICE, "%s", str);
+		ULOG_NOTE("%s", str);
 #ifdef SHOW_BOOT_ON_CONSOLE
 		fprintf(stderr, "%s\n", str);
 #endif
-- 
2.11.0




More information about the Lede-dev mailing list