diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-12-03 09:19:54 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-12-03 09:19:54 +0000 |
commit | b186d980d6060195d01048bb3a083739137b6c21 (patch) | |
tree | f64b2d63850be12ce3081b2000784aa57ac29656 /sysklogd | |
parent | 77619b9dda2b0550fea519fba05f7d9790ef7eaf (diff) | |
download | busybox-w32-b186d980d6060195d01048bb3a083739137b6c21.tar.gz busybox-w32-b186d980d6060195d01048bb3a083739137b6c21.tar.bz2 busybox-w32-b186d980d6060195d01048bb3a083739137b6c21.zip |
Stuf
Diffstat (limited to 'sysklogd')
-rw-r--r-- | sysklogd/syslogd.c | 125 |
1 files changed, 115 insertions, 10 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 736adf7d1..3c7b0170d 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -32,6 +32,12 @@ | |||
32 | #include <signal.h> | 32 | #include <signal.h> |
33 | #include <ctype.h> | 33 | #include <ctype.h> |
34 | #include <netdb.h> | 34 | #include <netdb.h> |
35 | #include <sys/klog.h> | ||
36 | #include <errno.h> | ||
37 | #include <paths.h> | ||
38 | |||
39 | #define ksyslog klogctl | ||
40 | extern int ksyslog(int type, char *buf, int len); | ||
35 | 41 | ||
36 | 42 | ||
37 | /* SYSLOG_NAMES defined to pull some extra junk from syslog.h */ | 43 | /* SYSLOG_NAMES defined to pull some extra junk from syslog.h */ |
@@ -40,8 +46,6 @@ | |||
40 | 46 | ||
41 | /* Path for the file where all log messages are written */ | 47 | /* Path for the file where all log messages are written */ |
42 | #define __LOG_FILE "/var/log/messages" | 48 | #define __LOG_FILE "/var/log/messages" |
43 | /* Path to the current console device */ | ||
44 | #define __DEV_CONSOLE "/dev/console" | ||
45 | 49 | ||
46 | 50 | ||
47 | static char* logFilePath = __LOG_FILE; | 51 | static char* logFilePath = __LOG_FILE; |
@@ -58,7 +62,7 @@ static const char syslogd_usage[] = | |||
58 | "\t-n\tDo not fork into the background (for when run by init)\n" | 62 | "\t-n\tDo not fork into the background (for when run by init)\n" |
59 | "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; | 63 | "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; |
60 | 64 | ||
61 | 65 | static int kmsg; | |
62 | 66 | ||
63 | /* try to open up the specified device */ | 67 | /* try to open up the specified device */ |
64 | static int device_open(char *device, int mode) | 68 | static int device_open(char *device, int mode) |
@@ -92,7 +96,7 @@ static void message(char *fmt, ...) | |||
92 | close(fd); | 96 | close(fd); |
93 | } else { | 97 | } else { |
94 | /* Always send console messages to /dev/console so people will see them. */ | 98 | /* Always send console messages to /dev/console so people will see them. */ |
95 | if ((fd = device_open(__DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) { | 99 | if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) { |
96 | va_start(arguments, fmt); | 100 | va_start(arguments, fmt); |
97 | vdprintf(fd, fmt, arguments); | 101 | vdprintf(fd, fmt, arguments); |
98 | va_end(arguments); | 102 | va_end(arguments); |
@@ -250,20 +254,112 @@ static void doSyslogd(void) | |||
250 | close(fd); | 254 | close(fd); |
251 | } | 255 | } |
252 | 256 | ||
257 | static void klogd_signal(int sig) | ||
258 | { | ||
259 | //ksyslog(7, NULL, 0); | ||
260 | //ksyslog(0, 0, 0); | ||
261 | logMessage(LOG_SYSLOG|LOG_INFO, "Kernel log daemon terminating."); | ||
262 | exit( TRUE); | ||
263 | } | ||
264 | |||
265 | |||
266 | static void doKlogd(void) | ||
267 | { | ||
268 | int priority=LOG_INFO; | ||
269 | struct stat sb; | ||
270 | char log_buffer[4096]; | ||
271 | |||
272 | /* Set up sig handlers */ | ||
273 | signal(SIGINT, klogd_signal); | ||
274 | signal(SIGKILL, klogd_signal); | ||
275 | signal(SIGTERM, klogd_signal); | ||
276 | signal(SIGHUP, klogd_signal); | ||
277 | logMessage(LOG_SYSLOG|LOG_INFO, "klogd started: " | ||
278 | "BusyBox v" BB_VER " (" BB_BT ") multi-call binary"); | ||
279 | |||
280 | //ksyslog(1, NULL, 0); | ||
281 | if ( ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) || | ||
282 | ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 ) ) { | ||
283 | char message[80]; | ||
284 | snprintf(message, 79, "klogd: Cannot open %s, " \ | ||
285 | "%d - %s.\n", _PATH_KLOG, errno, strerror(errno)); | ||
286 | logMessage(LOG_SYSLOG|LOG_ERR, message); | ||
287 | klogd_signal(0); | ||
288 | } | ||
289 | while (1) { | ||
290 | memset(log_buffer, '\0', sizeof(log_buffer)); | ||
291 | if ( read(kmsg, log_buffer, sizeof(log_buffer)-1) < 0 ) { | ||
292 | char message[80]; | ||
293 | if ( errno == EINTR ) | ||
294 | continue; | ||
295 | snprintf(message, 79, "klogd: Cannot read proc file system: %d - %s.\n", | ||
296 | errno, strerror(errno)); | ||
297 | logMessage(LOG_SYSLOG|LOG_ERR, message); | ||
298 | klogd_signal(0); | ||
299 | } | ||
300 | #if 0 | ||
301 | if ( ksyslog(2, log_buffer, sizeof(log_buffer)) < 0 ) { | ||
302 | char message[80]; | ||
303 | if ( errno == EINTR ) | ||
304 | continue; | ||
305 | snprintf(message, 79, "klogd: Error return from sys_sycall: " \ | ||
306 | "%d - %s.\n", errno, strerror(errno)); | ||
307 | logMessage(LOG_SYSLOG|LOG_ERR, message); | ||
308 | exit(1); | ||
309 | } | ||
310 | #endif | ||
311 | fprintf(stderr, "the kernel says '%s'\n", log_buffer); | ||
312 | if ( *log_buffer == '<' ) | ||
313 | { | ||
314 | switch ( *(log_buffer+1) ) | ||
315 | { | ||
316 | case '0': | ||
317 | priority = LOG_EMERG; | ||
318 | break; | ||
319 | case '1': | ||
320 | priority = LOG_ALERT; | ||
321 | break; | ||
322 | case '2': | ||
323 | priority = LOG_CRIT; | ||
324 | break; | ||
325 | case '3': | ||
326 | priority = LOG_ERR; | ||
327 | break; | ||
328 | case '4': | ||
329 | priority = LOG_WARNING; | ||
330 | break; | ||
331 | case '5': | ||
332 | priority = LOG_NOTICE; | ||
333 | break; | ||
334 | case '6': | ||
335 | priority = LOG_INFO; | ||
336 | break; | ||
337 | case '7': | ||
338 | default: | ||
339 | priority = LOG_DEBUG; | ||
340 | } | ||
341 | *log_buffer += 3; | ||
342 | } | ||
343 | logMessage(LOG_KERN|priority, log_buffer); | ||
344 | } | ||
345 | |||
346 | } | ||
347 | |||
253 | 348 | ||
254 | extern int syslogd_main(int argc, char **argv) | 349 | extern int syslogd_main(int argc, char **argv) |
255 | { | 350 | { |
256 | int pid; | 351 | int pid, klogd_pid; |
257 | int doFork = TRUE; | 352 | int doFork = TRUE; |
353 | char **argv1=argv; | ||
258 | 354 | ||
259 | while (--argc > 0 && **(++argv) == '-') { | 355 | while (--argc > 0 && **(++argv1) == '-') { |
260 | while (*(++(*argv))) { | 356 | while (*(++(*argv1))) { |
261 | switch (**argv) { | 357 | switch (**argv1) { |
262 | case 'm': | 358 | case 'm': |
263 | if (--argc == 0) { | 359 | if (--argc == 0) { |
264 | usage(syslogd_usage); | 360 | usage(syslogd_usage); |
265 | } | 361 | } |
266 | MarkInterval = atoi(*(++argv))*60; | 362 | MarkInterval = atoi(*(++argv1))*60; |
267 | break; | 363 | break; |
268 | case 'n': | 364 | case 'n': |
269 | doFork = FALSE; | 365 | doFork = FALSE; |
@@ -272,7 +368,7 @@ extern int syslogd_main(int argc, char **argv) | |||
272 | if (--argc == 0) { | 368 | if (--argc == 0) { |
273 | usage(syslogd_usage); | 369 | usage(syslogd_usage); |
274 | } | 370 | } |
275 | logFilePath = *(++argv); | 371 | logFilePath = *(++argv1); |
276 | break; | 372 | break; |
277 | default: | 373 | default: |
278 | usage(syslogd_usage); | 374 | usage(syslogd_usage); |
@@ -285,11 +381,20 @@ extern int syslogd_main(int argc, char **argv) | |||
285 | if ( pid < 0 ) | 381 | if ( pid < 0 ) |
286 | exit( pid); | 382 | exit( pid); |
287 | else if ( pid == 0 ) { | 383 | else if ( pid == 0 ) { |
384 | strncpy(argv[0], "syslogd",strlen(argv[0])); | ||
288 | doSyslogd(); | 385 | doSyslogd(); |
289 | } | 386 | } |
290 | } else { | 387 | } else { |
291 | doSyslogd(); | 388 | doSyslogd(); |
292 | } | 389 | } |
390 | |||
391 | /* Start klogd process */ | ||
392 | klogd_pid = fork(); | ||
393 | if (klogd_pid == 0 ) { | ||
394 | strncpy(argv[0], "klogd", strlen(argv[0])); | ||
395 | doKlogd(); | ||
396 | } | ||
397 | |||
293 | exit( TRUE); | 398 | exit( TRUE); |
294 | } | 399 | } |
295 | 400 | ||