[OpenWrt-Devel] [PATCH procd 2/8] Log startup/shutdown to console

Michel Stam m.stam at fugro.nl
Thu Oct 2 08:56:17 EDT 2014


procd has the habit of logging startup/shutdown via
rcS to syslog, which is pointless in case of a
shutdown, and unlikely to be complete on a startup
(as syslog is not running). Write to /dev/console
instead.

Signed-off-by: Michel Stam <m.stam at fugro.nl>
---
 rcS.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/rcS.c b/rcS.c
index 4545621..e01fc49 100644
--- a/rcS.c
+++ b/rcS.c
@@ -18,10 +18,11 @@
 
 #include <libubox/uloop.h>
 #include <libubox/runqueue.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
-
+#include <paths.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <glob.h>
@@ -43,8 +44,9 @@ struct initd {
 static void pipe_cb(struct ustream *s, int bytes)
 {
 	char *newline, *str;
-	int len;
+	int len, console_fd;
 
+	console_fd = open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY | O_NONBLOCK);
 	do {
 		str = ustream_get_read_buf(s, NULL);
 		if (!str)
@@ -52,11 +54,11 @@ static void pipe_cb(struct ustream *s, int bytes)
 		newline = strchr(str, '\n');
 		if (!newline)
 			break;
-		*newline = 0;
 		len = newline + 1 - str;
-		syslog(0, "%s", str);
+		write(console_fd, str, len);
 		ustream_consume(s, len);
 	} while (1);
+	close(console_fd);
 }
 
 static void q_initd_run(struct runqueue *q, struct runqueue_task *t)
-- 
1.7.12.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list