diff options
author | Pavel Roskin <proski@gnu.org> | 2000-06-07 21:08:25 +0000 |
---|---|---|
committer | Pavel Roskin <proski@gnu.org> | 2000-06-07 21:08:25 +0000 |
commit | da10ec0eaaaaacbbd9dfb1b7ff84aab5a2de9e37 (patch) | |
tree | aecf83ac0c40ee2d7d14df0008fed0e2c6a18a70 /sysklogd | |
parent | 0024abcbbc633f4493b97c4b344ed636ea176f3c (diff) | |
download | busybox-w32-da10ec0eaaaaacbbd9dfb1b7ff84aab5a2de9e37.tar.gz busybox-w32-da10ec0eaaaaacbbd9dfb1b7ff84aab5a2de9e37.tar.bz2 busybox-w32-da10ec0eaaaaacbbd9dfb1b7ff84aab5a2de9e37.zip |
Syslogd will not go to background if "-n" is given. Better help
and argument checking
Diffstat (limited to 'sysklogd')
-rw-r--r-- | sysklogd/syslogd.c | 97 |
1 files changed, 52 insertions, 45 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 9a4af4926..c7906368d 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -69,12 +69,12 @@ static const char syslogd_usage[] = | |||
69 | "\nLinux system and kernel (provides klogd) logging utility.\n" | 69 | "\nLinux system and kernel (provides klogd) logging utility.\n" |
70 | "Note that this version of syslogd/klogd ignores /etc/syslog.conf.\n\n" | 70 | "Note that this version of syslogd/klogd ignores /etc/syslog.conf.\n\n" |
71 | "Options:\n" | 71 | "Options:\n" |
72 | "\t-m\tChange the mark timestamp interval. default=20min. 0=off\n" | 72 | "\t-m NUM\t\tInterval between MARK lines (default=20min, 0=off)\n" |
73 | "\t-n\tDo not fork into the background (for when run by init)\n" | 73 | "\t-n\t\tRun as a foreground process\n" |
74 | #ifdef BB_KLOGD | 74 | #ifdef BB_KLOGD |
75 | "\t-K\tDo not start up the klogd process (by default syslogd spawns klogd).\n" | 75 | "\t-K\t\tDo not start up the klogd process\n" |
76 | #endif | 76 | #endif |
77 | "\t-O\tSpecify an alternate log file. default=/var/log/messages\n" | 77 | "\t-O FILE\t\tUse an alternate log file (default=/var/log/messages)\n" |
78 | #endif | 78 | #endif |
79 | ; | 79 | ; |
80 | 80 | ||
@@ -170,6 +170,49 @@ static void domark(int sig) | |||
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | #define BUFSIZE 1023 | ||
174 | static void serveConnection (int conn) __attribute__ ((noreturn)); | ||
175 | static void serveConnection (int conn) | ||
176 | { | ||
177 | char buf[ BUFSIZE + 1 ]; | ||
178 | int n_read; | ||
179 | |||
180 | while ((n_read = read (conn, buf, BUFSIZE )) > 0) { | ||
181 | |||
182 | int pri = (LOG_USER | LOG_NOTICE); | ||
183 | char line[ BUFSIZE + 1 ]; | ||
184 | unsigned char c; | ||
185 | |||
186 | char *p = buf, *q = line; | ||
187 | |||
188 | buf[ n_read - 1 ] = '\0'; | ||
189 | |||
190 | while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) { | ||
191 | if (c == '<') { | ||
192 | /* Parse the magic priority number. */ | ||
193 | pri = 0; | ||
194 | while (isdigit (*(++p))) { | ||
195 | pri = 10 * pri + (*p - '0'); | ||
196 | } | ||
197 | if (pri & ~(LOG_FACMASK | LOG_PRIMASK)) | ||
198 | pri = (LOG_USER | LOG_NOTICE); | ||
199 | } else if (c == '\n') { | ||
200 | *q++ = ' '; | ||
201 | } else if (iscntrl (c) && (c < 0177)) { | ||
202 | *q++ = '^'; | ||
203 | *q++ = c ^ 0100; | ||
204 | } else { | ||
205 | *q++ = c; | ||
206 | } | ||
207 | p++; | ||
208 | } | ||
209 | *q = '\0'; | ||
210 | /* Now log it */ | ||
211 | logMessage (pri, line); | ||
212 | } | ||
213 | exit (0); | ||
214 | } | ||
215 | |||
173 | static void doSyslogd (void) __attribute__ ((noreturn)); | 216 | static void doSyslogd (void) __attribute__ ((noreturn)); |
174 | static void doSyslogd (void) | 217 | static void doSyslogd (void) |
175 | { | 218 | { |
@@ -251,47 +294,8 @@ static void doSyslogd (void) | |||
251 | continue; | 294 | continue; |
252 | } | 295 | } |
253 | 296 | ||
254 | if (pid > 0) { | 297 | if (pid == 0) |
255 | 298 | serveConnection (conn); | |
256 | # define BUFSIZE 1023 | ||
257 | char buf[ BUFSIZE + 1 ]; | ||
258 | int n_read; | ||
259 | |||
260 | while ((n_read = read (conn, buf, BUFSIZE )) > 0) { | ||
261 | |||
262 | int pri = (LOG_USER | LOG_NOTICE); | ||
263 | char line[ BUFSIZE + 1 ]; | ||
264 | unsigned char c; | ||
265 | |||
266 | char *p = buf, *q = line; | ||
267 | |||
268 | buf[ n_read - 1 ] = '\0'; | ||
269 | |||
270 | while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) { | ||
271 | if (c == '<') { | ||
272 | /* Parse the magic priority number. */ | ||
273 | pri = 0; | ||
274 | while (isdigit (*(++p))) { | ||
275 | pri = 10 * pri + (*p - '0'); | ||
276 | } | ||
277 | if (pri & ~(LOG_FACMASK | LOG_PRIMASK)) | ||
278 | pri = (LOG_USER | LOG_NOTICE); | ||
279 | } else if (c == '\n') { | ||
280 | *q++ = ' '; | ||
281 | } else if (iscntrl (c) && (c < 0177)) { | ||
282 | *q++ = '^'; | ||
283 | *q++ = c ^ 0100; | ||
284 | } else { | ||
285 | *q++ = c; | ||
286 | } | ||
287 | p++; | ||
288 | } | ||
289 | *q = '\0'; | ||
290 | /* Now log it */ | ||
291 | logMessage (pri, line); | ||
292 | } | ||
293 | exit (0); | ||
294 | } | ||
295 | close (conn); | 299 | close (conn); |
296 | } | 300 | } |
297 | } | 301 | } |
@@ -428,6 +432,9 @@ extern int syslogd_main(int argc, char **argv) | |||
428 | } | 432 | } |
429 | } | 433 | } |
430 | 434 | ||
435 | if (argc > 0) | ||
436 | usage(syslogd_usage); | ||
437 | |||
431 | /* Store away localhost's name before the fork */ | 438 | /* Store away localhost's name before the fork */ |
432 | gethostname(LocalHostName, sizeof(LocalHostName)); | 439 | gethostname(LocalHostName, sizeof(LocalHostName)); |
433 | if ((p = strchr(LocalHostName, '.'))) { | 440 | if ((p = strchr(LocalHostName, '.'))) { |