[BusyBox] "klogd -c" patch

Roman Shevchenko sher at xiit.kharkov.ua
Thu Dec 5 08:18:03 UTC 2002


Hi All!

Here is a small patch which adds handling of "-c n" option (console log level) to 
klogd. Hope it will be useful not only for me :-)

- SheR

=== busybox-klogd.patch begins ===
diff -ru busybox-0.60.5/klogd.c busybox-0.60.5-patched/klogd.c
--- busybox-0.60.5/klogd.c	Wed Sep 18 17:22:49 2002
+++ busybox-0.60.5-patched/klogd.c	Mon Dec  2 19:59:00 2002
@@ -50,6 +50,9 @@
 
 #include "busybox.h"
 
+/* Default console log level: use kernel defaults */
+int console_level = -1;
+
 static void klogd_signal(int sig)
 {
 	klogctl(7, NULL, 0);
@@ -76,6 +79,10 @@
 	/* "Open the log. Currently a NOP." */
 	klogctl(1, NULL, 0);
 
+	/* Set up console log level */
+	if (console_level != -1)
+		klogctl(8, NULL, console_level);
+
 	syslog_msg(LOG_SYSLOG, LOG_NOTICE, "klogd started: " BB_BANNER);
 
 	while (1) {
@@ -127,16 +134,26 @@
 #endif  /* __uClinux__ */
 
 	/* do normal option parsing */
-	while ((opt = getopt(argc, argv, "n")) > 0) {
+	while ((opt = getopt(argc, argv, "nc:")) > 0) {
 		switch (opt) {
 			case 'n':
 #ifndef __uClinux__	/* fork() not available in uClinux */
 				doFork = FALSE;
 #endif  /* __uClinux__ */
 				break;
+			case 'c':
+				console_level = atoi(optarg);
+				break;
 			default:
 				show_usage();
 		}
+	}
+
+	/* check given log level */
+	if (console_level < 1  &&  console_level > 8) {
+		fprintf(stdout, "klogd: invalid console log level "
+			"<%d> - ignored.\n", console_level);
+		console_level = -1;
 	}
 
 #ifndef __uClinux__	/* fork() not available in uClinux */
diff -ru busybox-0.60.5/usage.h busybox-0.60.5-patched/usage.h
--- busybox-0.60.5/usage.h	Mon Sep 30 23:59:58 2002
+++ busybox-0.60.5-patched/usage.h	Mon Dec  2 19:58:10 2002
@@ -844,10 +844,11 @@
 	"$ killall apache\n" 
 
 #define klogd_trivial_usage \
-	"-n"
+	"[-c n] [-n]"
 #define klogd_full_usage \
 	"Kernel logger.\n"\
 	"Options:\n"\
+	"\t-c n\tSets the default log level of console messages to n.\n"\
 	"\t-n\tRun as a foreground process."
 
 #define length_trivial_usage \
=== busybox-klogd.patch ends ===






More information about the busybox mailing list