diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-19 23:07:49 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-19 23:07:49 +0200 |
commit | 0016bcee374606e79c48a1a97479b0521f947942 (patch) | |
tree | cad91be9d3821dfb26f433b19ca0fb24d9c1ba8a | |
parent | ef6c6d8cfef071435ccf275ad404a501626b706c (diff) | |
download | busybox-w32-0016bcee374606e79c48a1a97479b0521f947942.tar.gz busybox-w32-0016bcee374606e79c48a1a97479b0521f947942.tar.bz2 busybox-w32-0016bcee374606e79c48a1a97479b0521f947942.zip |
klogd: do not log partial lines
function old new delta
overlapping_strcpy 15 18 +3
klogd_main 438 436 -2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/safe_strncpy.c | 11 | ||||
-rw-r--r-- | sysklogd/klogd.c | 19 |
2 files changed, 18 insertions, 12 deletions
diff --git a/libbb/safe_strncpy.c b/libbb/safe_strncpy.c index 8eb6a014f..5eb0db0bd 100644 --- a/libbb/safe_strncpy.c +++ b/libbb/safe_strncpy.c | |||
@@ -20,8 +20,13 @@ char* FAST_FUNC safe_strncpy(char *dst, const char *src, size_t size) | |||
20 | /* Like strcpy but can copy overlapping strings. */ | 20 | /* Like strcpy but can copy overlapping strings. */ |
21 | void FAST_FUNC overlapping_strcpy(char *dst, const char *src) | 21 | void FAST_FUNC overlapping_strcpy(char *dst, const char *src) |
22 | { | 22 | { |
23 | while ((*dst = *src) != '\0') { | 23 | /* Cheap optimization for dst == src case - |
24 | dst++; | 24 | * better to have it here than in many callers. |
25 | src++; | 25 | */ |
26 | if (dst != src) { | ||
27 | while ((*dst = *src) != '\0') { | ||
28 | dst++; | ||
29 | src++; | ||
30 | } | ||
26 | } | 31 | } |
27 | } | 32 | } |
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 6766b649d..0d4c2578d 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -132,7 +132,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
132 | int i = 0; | 132 | int i = 0; |
133 | char *opt_c; | 133 | char *opt_c; |
134 | int opt; | 134 | int opt; |
135 | int used = 0; | 135 | int used; |
136 | 136 | ||
137 | opt = getopt32(argv, "c:n", &opt_c); | 137 | opt = getopt32(argv, "c:n", &opt_c); |
138 | if (opt & OPT_LEVEL) { | 138 | if (opt & OPT_LEVEL) { |
@@ -159,6 +159,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
159 | 159 | ||
160 | syslog(LOG_NOTICE, "klogd started: %s", bb_banner); | 160 | syslog(LOG_NOTICE, "klogd started: %s", bb_banner); |
161 | 161 | ||
162 | used = 0; | ||
162 | while (!bb_got_signal) { | 163 | while (!bb_got_signal) { |
163 | int n; | 164 | int n; |
164 | int priority; | 165 | int priority; |
@@ -175,22 +176,22 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
175 | } | 176 | } |
176 | start[n] = '\0'; | 177 | start[n] = '\0'; |
177 | 178 | ||
178 | /* klogctl buffer parsing modelled after code in dmesg.c */ | ||
179 | /* Process each newline-terminated line in the buffer */ | 179 | /* Process each newline-terminated line in the buffer */ |
180 | start = log_buffer; | 180 | start = log_buffer; |
181 | while (1) { | 181 | while (1) { |
182 | char *newline = strchrnul(start, '\n'); | 182 | char *newline = strchrnul(start, '\n'); |
183 | 183 | ||
184 | if (*newline == '\0') { | 184 | if (*newline == '\0') { |
185 | /* This line is incomplete... */ | 185 | /* This line is incomplete */ |
186 | if (start != log_buffer) { | 186 | |
187 | /* move it to the front of the buffer */ | 187 | /* move it to the front of the buffer */ |
188 | overlapping_strcpy(log_buffer, start); | 188 | overlapping_strcpy(log_buffer, start); |
189 | used = newline - start; | 189 | used = newline - start; |
190 | /* don't log it yet */ | 190 | if (used < KLOGD_LOGBUF_SIZE-1) { |
191 | /* buffer isn't full */ | ||
191 | break; | 192 | break; |
192 | } | 193 | } |
193 | /* ...but if buffer is full, log it anyway */ | 194 | /* buffer is full, log it anyway */ |
194 | used = 0; | 195 | used = 0; |
195 | newline = NULL; | 196 | newline = NULL; |
196 | } else { | 197 | } else { |