[BusyBox] Syslogd patch again

Pavel Roskin pavel_roskin at geocities.com
Mon Jun 5 10:45:53 MDT 2000


Hello!

I don't want to use my write permissions to apply non-trivial patches
before the consensus is achieved.

I'll try to document and explain all the changes regarding syslogd.

First of all - how do I rebuild busybox.pod? I have updated it manually,
but probably this is not the best way.

The help used to promise that "syslogd -n" will not run fork(). This is no
longer possible - syslogd needs to fork. Another thing can be done (and is
done by my patch) - the initial process will not exit, so "init" will not
restart "syslogd".

The help has been modified to remove the word "fork" as it is not
relevant. Also the help message now mentions options with arguments and is
better formatted.

If there are options that "syslogd" doesn't understand it prints the usage
information now. It used to ignore unknown options.

Finally, the whole function of the child process has been moved to a
separate function serveConnection. This code used to be in the
doSyslogd() function. The reasons for moving this code to a separate
function are:

this code is executed by a separate process
this code shares only one variable (conn) with the rest of doSyslogd()
doSyslogd() is too big
the code in question was indented by at least 6 tabs!

Regards,
Pavel Roskin

=============================
diff -ur -x CVS -x *.h busybox.ea/Changelog busybox/Changelog
--- busybox.ea/Changelog	Mon Jun  5 08:57:02 2000
+++ busybox/Changelog	Mon Jun  5 09:16:44 2000
@@ -50,6 +50,8 @@
 	* Fixed all fatalError() calls lacking a "\n", thanks to Pavel Roskin.
 	* Fixed a segfault in yes when no args were given -- Pavel Roskin.
 	* Simplified freeramdisk and added argument checking -- Pavel Roskin. 
+	* Syslogd will not go to background if "-n" is given. Better help
+	    and argument checking -- Pavel Roskin. 
 	* More doc updates
 
 
diff -ur -x CVS -x *.h busybox.ea/docs/busybox.pod busybox/docs/busybox.pod
--- busybox.ea/docs/busybox.pod	Thu Jun  1 23:21:37 2000
+++ busybox/docs/busybox.pod	Mon Jun  5 09:24:01 2000
@@ -1527,11 +1527,10 @@
 Note that this version of syslogd/klogd ignores /etc/syslog.conf.
 
 Options:
-
-        -m      Change the mark timestamp interval. default=20min. 0=off
-        -n      Do not fork into the background (for when run by init)
-        -K      Do not start up the klogd process (by default syslogd spawns klogd).
-        -O      Specify an alternate log file.  default=/var/log/messages
+	-m NUM		Interval between MARK lines (default=20min, 0=off)
+	-n		Run as a foreground process
+	-K		Do not start up the klogd process
+	-O FILE		Use an alternate log file (default=/var/log/messages)
 
 -------------------------------
 
diff -ur -x CVS -x *.h busybox.ea/syslogd.c busybox/syslogd.c
--- busybox.ea/syslogd.c	Thu Jun  1 23:21:33 2000
+++ busybox/syslogd.c	Fri Jun  2 09:22:56 2000
@@ -69,12 +69,12 @@
 	"\nLinux system and kernel (provides klogd) logging utility.\n"
 	"Note that this version of syslogd/klogd ignores /etc/syslog.conf.\n\n"
 	"Options:\n"
-	"\t-m\tChange the mark timestamp interval. default=20min. 0=off\n"
-	"\t-n\tDo not fork into the background (for when run by init)\n"
+	"\t-m NUM\t\tInterval between MARK lines (default=20min, 0=off)\n"
+	"\t-n\t\tRun as a foreground process\n"
 #ifdef BB_KLOGD
-	"\t-K\tDo not start up the klogd process (by default syslogd spawns klogd).\n"
+	"\t-K\t\tDo not start up the klogd process\n"
 #endif
-	"\t-O\tSpecify an alternate log file.  default=/var/log/messages\n"
+	"\t-O FILE\t\tUse an alternate log file (default=/var/log/messages)\n"
 #endif
 	;
 
@@ -170,6 +170,49 @@
 	}
 }
 
+#define BUFSIZE 1023
+static void serveConnection (int conn) __attribute__ ((noreturn));
+static void serveConnection (int conn)
+{
+	char   buf[ BUFSIZE + 1 ];
+	int    n_read;
+
+	while ((n_read = read (conn, buf, BUFSIZE )) > 0) {
+
+		int           pri = (LOG_USER | LOG_NOTICE);
+		char          line[ BUFSIZE + 1 ];
+		unsigned char c;
+
+		char *p = buf, *q = line;
+
+		buf[ n_read - 1 ] = '\0';
+
+		while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
+			if (c == '<') {
+			/* Parse the magic priority number. */
+				pri = 0;
+				while (isdigit (*(++p))) {
+					pri = 10 * pri + (*p - '0');
+				}
+				if (pri & ~(LOG_FACMASK | LOG_PRIMASK))
+					pri = (LOG_USER | LOG_NOTICE);
+			} else if (c == '\n') {
+				*q++ = ' ';
+			} else if (iscntrl (c) && (c < 0177)) {
+				*q++ = '^';
+				*q++ = c ^ 0100;
+			} else {
+				*q++ = c;
+			}
+			p++;
+		}
+		*q = '\0';
+		/* Now log it */
+		logMessage (pri, line);
+	}
+	exit (0);
+}
+
 static void doSyslogd (void) __attribute__ ((noreturn));
 static void doSyslogd (void)
 {
@@ -251,47 +294,8 @@
 						continue;
 					}
 
-					if (pid > 0) {
-
-#						define BUFSIZE 1023
-						char   buf[ BUFSIZE + 1 ];
-						int    n_read;
-
-						while ((n_read = read (conn, buf, BUFSIZE )) > 0) {
-
-							int           pri = (LOG_USER | LOG_NOTICE);
-							char          line[ BUFSIZE + 1 ];
-							unsigned char c;
-
-							char *p = buf, *q = line;
-
-							buf[ n_read - 1 ] = '\0';
-
-							while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
-								if (c == '<') {
-								/* Parse the magic priority number. */
-									pri = 0;
-									while (isdigit (*(++p))) {
-										pri = 10 * pri + (*p - '0');
-									}
-									if (pri & ~(LOG_FACMASK | LOG_PRIMASK))
-										pri = (LOG_USER | LOG_NOTICE);
-								} else if (c == '\n') {
-									*q++ = ' ';
-								} else if (iscntrl (c) && (c < 0177)) {
-									*q++ = '^';
-									*q++ = c ^ 0100;
-								} else {
-									*q++ = c;
-								}
-								p++;
-							}
-							*q = '\0';
-							/* Now log it */
-							logMessage (pri, line);
-						}
-						exit (0);
-					}
+					if (pid == 0)
+						serveConnection (conn);
 					close (conn);
 				}
 			}
@@ -427,6 +431,9 @@
 			}
 		}
 	}
+
+	if (argc > 0)
+		usage(syslogd_usage);
 
 	/* Store away localhost's name before the fork */
 	gethostname(LocalHostName, sizeof(LocalHostName));
=============================







More information about the busybox mailing list