diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-04 03:07:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-04 03:07:57 +0000 |
commit | e428e9d43b998a251ef7ad9d131459872ce4b4ff (patch) | |
tree | 6aa1ef3ed663aebd19cdeade0b97542813d77427 /sysklogd | |
parent | b8429fb1f45a35b36adeb44f90cd6842c2df7791 (diff) | |
download | busybox-w32-e428e9d43b998a251ef7ad9d131459872ce4b4ff.tar.gz busybox-w32-e428e9d43b998a251ef7ad9d131459872ce4b4ff.tar.bz2 busybox-w32-e428e9d43b998a251ef7ad9d131459872ce4b4ff.zip |
klogd: small optimizations
(btw, I looked into syslogd... that's frightening!)
Diffstat (limited to 'sysklogd')
-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 f735d9fc1..97b419104 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -25,8 +25,7 @@ static void klogd_signal(int sig ATTRIBUTE_UNUSED) | |||
25 | { | 25 | { |
26 | klogctl(7, NULL, 0); | 26 | klogctl(7, NULL, 0); |
27 | klogctl(0, 0, 0); | 27 | klogctl(0, 0, 0); |
28 | /* logMessage(0, "Kernel log daemon exiting."); */ | 28 | syslog(LOG_NOTICE, "Kernel log daemon exiting"); |
29 | syslog(LOG_NOTICE, "Kernel log daemon exiting."); | ||
30 | exit(EXIT_SUCCESS); | 29 | exit(EXIT_SUCCESS); |
31 | } | 30 | } |
32 | 31 | ||
@@ -38,29 +37,25 @@ static void klogd_signal(int sig ATTRIBUTE_UNUSED) | |||
38 | int klogd_main(int argc, char **argv) | 37 | int klogd_main(int argc, char **argv) |
39 | { | 38 | { |
40 | RESERVE_CONFIG_BUFFER(log_buffer, KLOGD_LOGBUF_SIZE); | 39 | RESERVE_CONFIG_BUFFER(log_buffer, KLOGD_LOGBUF_SIZE); |
41 | int console_log_level = -1; | 40 | int console_log_level = console_log_level; /* for gcc */ |
42 | int priority = LOG_INFO; | 41 | int priority = LOG_INFO; |
43 | int i, n, lastc; | 42 | int i, n, lastc; |
44 | char *start; | 43 | char *start; |
45 | 44 | ||
46 | { | 45 | /* do normal option parsing */ |
47 | unsigned opt; | 46 | n = getopt32(argc, argv, "c:n", &start); |
48 | 47 | ||
49 | /* do normal option parsing */ | 48 | if (n & OPT_LEVEL) { |
50 | opt = getopt32(argc, argv, "c:n", &start); | 49 | /* Valid levels are between 1 and 8 */ |
51 | 50 | console_log_level = xatoul_range(start, 1, 8); | |
52 | if (opt & OPT_LEVEL) { | 51 | } |
53 | /* Valid levels are between 1 and 8 */ | ||
54 | console_log_level = xatoul_range(start, 1, 8); | ||
55 | } | ||
56 | 52 | ||
57 | if (!(opt & OPT_FOREGROUND)) { | 53 | if (!(n & OPT_FOREGROUND)) { |
58 | #ifdef BB_NOMMU | 54 | #ifdef BB_NOMMU |
59 | vfork_daemon_rexec(0, 1, argc, argv, "-n"); | 55 | vfork_daemon_rexec(0, 1, argc, argv, "-n"); |
60 | #else | 56 | #else |
61 | xdaemon(0, 1); | 57 | xdaemon(0, 1); |
62 | #endif | 58 | #endif |
63 | } | ||
64 | } | 59 | } |
65 | 60 | ||
66 | openlog("kernel", 0, LOG_KERN); | 61 | openlog("kernel", 0, LOG_KERN); |
@@ -75,7 +70,7 @@ int klogd_main(int argc, char **argv) | |||
75 | klogctl(1, NULL, 0); | 70 | klogctl(1, NULL, 0); |
76 | 71 | ||
77 | /* Set level of kernel console messaging.. */ | 72 | /* Set level of kernel console messaging.. */ |
78 | if (console_log_level != -1) | 73 | if (n & OPT_LEVEL) |
79 | klogctl(8, NULL, console_log_level); | 74 | klogctl(8, NULL, console_log_level); |
80 | 75 | ||
81 | syslog(LOG_NOTICE, "klogd started: %s", BB_BANNER); | 76 | syslog(LOG_NOTICE, "klogd started: %s", BB_BANNER); |
@@ -83,13 +78,14 @@ int klogd_main(int argc, char **argv) | |||
83 | while (1) { | 78 | while (1) { |
84 | /* Use kernel syscalls */ | 79 | /* Use kernel syscalls */ |
85 | memset(log_buffer, '\0', KLOGD_LOGBUF_SIZE); | 80 | memset(log_buffer, '\0', KLOGD_LOGBUF_SIZE); |
86 | n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE); | 81 | /* It will be null-terminted */ |
82 | n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1); | ||
87 | if (n < 0) { | 83 | if (n < 0) { |
88 | if (errno == EINTR) | 84 | if (errno == EINTR) |
89 | continue; | 85 | continue; |
90 | syslog(LOG_ERR, "klogd: Error from sys_sycall: %d - %m.\n", | 86 | syslog(LOG_ERR, "klogd: error from klogctl(2): %d - %m", |
91 | errno); | 87 | errno); |
92 | exit(EXIT_FAILURE); | 88 | break; |
93 | } | 89 | } |
94 | 90 | ||
95 | /* klogctl buffer parsing modelled after code in dmesg.c */ | 91 | /* klogctl buffer parsing modelled after code in dmesg.c */ |
@@ -97,10 +93,15 @@ int klogd_main(int argc, char **argv) | |||
97 | lastc = '\0'; | 93 | lastc = '\0'; |
98 | for (i = 0; i < n; i++) { | 94 | for (i = 0; i < n; i++) { |
99 | if (lastc == '\0' && log_buffer[i] == '<') { | 95 | if (lastc == '\0' && log_buffer[i] == '<') { |
100 | priority = 0; | ||
101 | i++; | 96 | i++; |
102 | while (log_buffer[i] >= '0' && log_buffer[i] <= '9') { | 97 | // kernel never ganerates multi-digit prios |
103 | priority = priority * 10 + (log_buffer[i] - '0'); | 98 | //priority = 0; |
99 | //while (log_buffer[i] >= '0' && log_buffer[i] <= '9') { | ||
100 | // priority = priority * 10 + (log_buffer[i] - '0'); | ||
101 | // i++; | ||
102 | //} | ||
103 | if (isdigit(log_buffer[i])) { | ||
104 | priority = (log_buffer[i] - '0'); | ||
104 | i++; | 105 | i++; |
105 | } | 106 | } |
106 | if (log_buffer[i] == '>') | 107 | if (log_buffer[i] == '>') |
@@ -119,5 +120,5 @@ int klogd_main(int argc, char **argv) | |||
119 | if (ENABLE_FEATURE_CLEAN_UP) | 120 | if (ENABLE_FEATURE_CLEAN_UP) |
120 | RELEASE_CONFIG_BUFFER(log_buffer); | 121 | RELEASE_CONFIG_BUFFER(log_buffer); |
121 | 122 | ||
122 | return EXIT_SUCCESS; | 123 | return EXIT_FAILURE; |
123 | } | 124 | } |