diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-17 14:12:10 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-17 14:12:10 +0000 |
commit | c84520d73dbe100449d84241ec0df9d02ee0fc4d (patch) | |
tree | 8798d754e514c869fa98243fd5db07ea1faa43df /sysklogd | |
parent | d818dcc72adb995309e5423382a825e9e342c971 (diff) | |
download | busybox-w32-c84520d73dbe100449d84241ec0df9d02ee0fc4d.tar.gz busybox-w32-c84520d73dbe100449d84241ec0df9d02ee0fc4d.tar.bz2 busybox-w32-c84520d73dbe100449d84241ec0df9d02ee0fc4d.zip |
klogd: code de-obfuscation with small code size reduction
Diffstat (limited to 'sysklogd')
-rw-r--r-- | sysklogd/klogd.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 47c2c7252..cca6f5671 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -32,12 +32,12 @@ static void klogd_signal(int sig ATTRIBUTE_UNUSED) | |||
32 | #define OPT_LEVEL 1 | 32 | #define OPT_LEVEL 1 |
33 | #define OPT_FOREGROUND 2 | 33 | #define OPT_FOREGROUND 2 |
34 | 34 | ||
35 | #define KLOGD_LOGBUF_SIZE 4096 | 35 | #define KLOGD_LOGBUF_SIZE BUFSIZ |
36 | #define log_buffer bb_common_bufsiz1 | ||
36 | 37 | ||
37 | int klogd_main(int argc, char **argv); | 38 | int klogd_main(int argc, char **argv); |
38 | int klogd_main(int argc, char **argv) | 39 | int klogd_main(int argc, char **argv) |
39 | { | 40 | { |
40 | RESERVE_CONFIG_BUFFER(log_buffer, KLOGD_LOGBUF_SIZE); | ||
41 | int i = i; /* silence gcc */ | 41 | int i = i; /* silence gcc */ |
42 | char *start; | 42 | char *start; |
43 | 43 | ||
@@ -53,7 +53,7 @@ int klogd_main(int argc, char **argv) | |||
53 | #ifdef BB_NOMMU | 53 | #ifdef BB_NOMMU |
54 | vfork_daemon_rexec(0, 1, argc, argv, "-n"); | 54 | vfork_daemon_rexec(0, 1, argc, argv, "-n"); |
55 | #else | 55 | #else |
56 | xdaemon(0, 1); | 56 | bb_daemonize(); |
57 | #endif | 57 | #endif |
58 | } | 58 | } |
59 | 59 | ||
@@ -68,35 +68,34 @@ int klogd_main(int argc, char **argv) | |||
68 | /* "Open the log. Currently a NOP." */ | 68 | /* "Open the log. Currently a NOP." */ |
69 | klogctl(1, NULL, 0); | 69 | klogctl(1, NULL, 0); |
70 | 70 | ||
71 | /* Set level of kernel console messaging.. */ | 71 | /* Set level of kernel console messaging. */ |
72 | if (option_mask32 & OPT_LEVEL) | 72 | if (option_mask32 & OPT_LEVEL) |
73 | klogctl(8, NULL, i); | 73 | klogctl(8, NULL, i); |
74 | 74 | ||
75 | syslog(LOG_NOTICE, "klogd started: %s", BB_BANNER); | 75 | syslog(LOG_NOTICE, "klogd started: %s", BB_BANNER); |
76 | 76 | ||
77 | /* Note: this code does not detect incomplete messages | ||
78 | * (messages not ending with '\n' or just when kernel | ||
79 | * generates too many messages for us to keep up) | ||
80 | * and will split them in two separate lines */ | ||
77 | while (1) { | 81 | while (1) { |
78 | int n; | 82 | int n; |
79 | int priority; | 83 | int priority; |
80 | char lastc; | ||
81 | 84 | ||
82 | /* Use kernel syscalls */ | ||
83 | memset(log_buffer, '\0', KLOGD_LOGBUF_SIZE); | ||
84 | /* It will be null-terminted */ | ||
85 | n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1); | 85 | n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1); |
86 | if (n < 0) { | 86 | if (n < 0) { |
87 | if (errno == EINTR) | 87 | if (errno == EINTR) |
88 | continue; | 88 | continue; |
89 | syslog(LOG_ERR, "klogd: error from klogctl(2): %d - %m", | 89 | syslog(LOG_ERR, "klogd: error from klogctl(2): %d - %m", |
90 | errno); | 90 | errno); |
91 | break; | 91 | break; |
92 | } | 92 | } |
93 | 93 | log_buffer[n] = '\n'; | |
94 | /* klogctl buffer parsing modelled after code in dmesg.c */ | 94 | i = 0; |
95 | start = &log_buffer[0]; | 95 | while (i < n) { |
96 | lastc = '\0'; | 96 | priority = LOG_INFO; |
97 | priority = LOG_INFO; | 97 | start = &log_buffer[i]; |
98 | for (i = 0; i < n; i++) { | 98 | if (log_buffer[i] == '<') { |
99 | if (lastc == '\0' && log_buffer[i] == '<') { | ||
100 | i++; | 99 | i++; |
101 | // kernel never ganerates multi-digit prios | 100 | // kernel never ganerates multi-digit prios |
102 | //priority = 0; | 101 | //priority = 0; |
@@ -112,17 +111,13 @@ int klogd_main(int argc, char **argv) | |||
112 | i++; | 111 | i++; |
113 | start = &log_buffer[i]; | 112 | start = &log_buffer[i]; |
114 | } | 113 | } |
115 | if (log_buffer[i] == '\n') { | 114 | while (log_buffer[i] != '\n') |
116 | log_buffer[i] = '\0'; /* zero terminate this message */ | 115 | i++; |
117 | syslog(priority, "%s", start); | 116 | log_buffer[i] = '\0'; |
118 | start = &log_buffer[i + 1]; | 117 | syslog(priority, "%s", start); |
119 | priority = LOG_INFO; | 118 | i++; |
120 | } | ||
121 | lastc = log_buffer[i]; | ||
122 | } | 119 | } |
123 | } | 120 | } |
124 | if (ENABLE_FEATURE_CLEAN_UP) | ||
125 | RELEASE_CONFIG_BUFFER(log_buffer); | ||
126 | 121 | ||
127 | return EXIT_FAILURE; | 122 | return EXIT_FAILURE; |
128 | } | 123 | } |