diff options
Diffstat (limited to 'sysklogd/klogd.c')
-rw-r--r-- | sysklogd/klogd.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index f735d9f..97b4191 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c @@ -25,8 +25,7 @@ static void klogd_signal(int sig ATTRIBUTE_UNUSED) { klogctl(7, NULL, 0); klogctl(0, 0, 0); - /* logMessage(0, "Kernel log daemon exiting."); */ - syslog(LOG_NOTICE, "Kernel log daemon exiting."); + syslog(LOG_NOTICE, "Kernel log daemon exiting"); exit(EXIT_SUCCESS); } @@ -38,29 +37,25 @@ static void klogd_signal(int sig ATTRIBUTE_UNUSED) int klogd_main(int argc, char **argv) { RESERVE_CONFIG_BUFFER(log_buffer, KLOGD_LOGBUF_SIZE); - int console_log_level = -1; + int console_log_level = console_log_level; /* for gcc */ int priority = LOG_INFO; int i, n, lastc; char *start; - { - unsigned opt; + /* do normal option parsing */ + n = getopt32(argc, argv, "c:n", &start); - /* do normal option parsing */ - opt = getopt32(argc, argv, "c:n", &start); - - if (opt & OPT_LEVEL) { - /* Valid levels are between 1 and 8 */ - console_log_level = xatoul_range(start, 1, 8); - } + if (n & OPT_LEVEL) { + /* Valid levels are between 1 and 8 */ + console_log_level = xatoul_range(start, 1, 8); + } - if (!(opt & OPT_FOREGROUND)) { + if (!(n & OPT_FOREGROUND)) { #ifdef BB_NOMMU - vfork_daemon_rexec(0, 1, argc, argv, "-n"); + vfork_daemon_rexec(0, 1, argc, argv, "-n"); #else - xdaemon(0, 1); + xdaemon(0, 1); #endif - } } openlog("kernel", 0, LOG_KERN); @@ -75,7 +70,7 @@ int klogd_main(int argc, char **argv) klogctl(1, NULL, 0); /* Set level of kernel console messaging.. */ - if (console_log_level != -1) + if (n & OPT_LEVEL) klogctl(8, NULL, console_log_level); syslog(LOG_NOTICE, "klogd started: %s", BB_BANNER); @@ -83,13 +78,14 @@ int klogd_main(int argc, char **argv) while (1) { /* Use kernel syscalls */ memset(log_buffer, '\0', KLOGD_LOGBUF_SIZE); - n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE); + /* It will be null-terminted */ + n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1); if (n < 0) { if (errno == EINTR) continue; - syslog(LOG_ERR, "klogd: Error from sys_sycall: %d - %m.\n", + syslog(LOG_ERR, "klogd: error from klogctl(2): %d - %m", errno); - exit(EXIT_FAILURE); + break; } /* klogctl buffer parsing modelled after code in dmesg.c */ @@ -97,10 +93,15 @@ int klogd_main(int argc, char **argv) lastc = '\0'; for (i = 0; i < n; i++) { if (lastc == '\0' && log_buffer[i] == '<') { - priority = 0; i++; - while (log_buffer[i] >= '0' && log_buffer[i] <= '9') { - priority = priority * 10 + (log_buffer[i] - '0'); + // kernel never ganerates multi-digit prios + //priority = 0; + //while (log_buffer[i] >= '0' && log_buffer[i] <= '9') { + // priority = priority * 10 + (log_buffer[i] - '0'); + // i++; + //} + if (isdigit(log_buffer[i])) { + priority = (log_buffer[i] - '0'); i++; } if (log_buffer[i] == '>') @@ -119,5 +120,5 @@ int klogd_main(int argc, char **argv) if (ENABLE_FEATURE_CLEAN_UP) RELEASE_CONFIG_BUFFER(log_buffer); - return EXIT_SUCCESS; + return EXIT_FAILURE; } |