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) |
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 @@ #include <signal.h> #include <ctype.h> #include <netdb.h> +#include <sys/klog.h> +#include <errno.h> +#include <paths.h> + +#define ksyslog klogctl +extern int ksyslog(int type, char *buf, int len); /* SYSLOG_NAMES defined to pull some extra junk from syslog.h */ @@ -40,8 +46,6 @@ /* Path for the file where all log messages are written */ #define __LOG_FILE "/var/log/messages" -/* Path to the current console device */ -#define __DEV_CONSOLE "/dev/console" static char* logFilePath = __LOG_FILE; @@ -58,7 +62,7 @@ static const char syslogd_usage[] = "\t-n\tDo not fork into the background (for when run by init)\n" "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; - +static int kmsg; /* try to open up the specified device */ static int device_open(char *device, int mode) @@ -92,7 +96,7 @@ static void message(char *fmt, ...) close(fd); } else { /* Always send console messages to /dev/console so people will see them. */ - if ((fd = device_open(__DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) { + if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) { va_start(arguments, fmt); vdprintf(fd, fmt, arguments); va_end(arguments); @@ -250,20 +254,112 @@ static void doSyslogd(void) close(fd); } +static void klogd_signal(int sig) +{ + //ksyslog(7, NULL, 0); + //ksyslog(0, 0, 0); + logMessage(LOG_SYSLOG|LOG_INFO, "Kernel log daemon terminating."); + exit( TRUE); +} + + +static void doKlogd(void) +{ + int priority=LOG_INFO; + struct stat sb; + char log_buffer[4096]; + + /* Set up sig handlers */ + signal(SIGINT, klogd_signal); + signal(SIGKILL, klogd_signal); + signal(SIGTERM, klogd_signal); + signal(SIGHUP, klogd_signal); + logMessage(LOG_SYSLOG|LOG_INFO, "klogd started: " + "BusyBox v" BB_VER " (" BB_BT ") multi-call binary"); + + //ksyslog(1, NULL, 0); + if ( ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) || + ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 ) ) { + char message[80]; + snprintf(message, 79, "klogd: Cannot open %s, " \ + "%d - %s.\n", _PATH_KLOG, errno, strerror(errno)); + logMessage(LOG_SYSLOG|LOG_ERR, message); + klogd_signal(0); + } + while (1) { + memset(log_buffer, '\0', sizeof(log_buffer)); + if ( read(kmsg, log_buffer, sizeof(log_buffer)-1) < 0 ) { + char message[80]; + if ( errno == EINTR ) + continue; + snprintf(message, 79, "klogd: Cannot read proc file system: %d - %s.\n", + errno, strerror(errno)); + logMessage(LOG_SYSLOG|LOG_ERR, message); + klogd_signal(0); + } +#if 0 + if ( ksyslog(2, log_buffer, sizeof(log_buffer)) < 0 ) { + char message[80]; + if ( errno == EINTR ) + continue; + snprintf(message, 79, "klogd: Error return from sys_sycall: " \ + "%d - %s.\n", errno, strerror(errno)); + logMessage(LOG_SYSLOG|LOG_ERR, message); + exit(1); + } +#endif + fprintf(stderr, "the kernel says '%s'\n", log_buffer); + if ( *log_buffer == '<' ) + { + switch ( *(log_buffer+1) ) + { + case '0': + priority = LOG_EMERG; + break; + case '1': + priority = LOG_ALERT; + break; + case '2': + priority = LOG_CRIT; + break; + case '3': + priority = LOG_ERR; + break; + case '4': + priority = LOG_WARNING; + break; + case '5': + priority = LOG_NOTICE; + break; + case '6': + priority = LOG_INFO; + break; + case '7': + default: + priority = LOG_DEBUG; + } + *log_buffer += 3; + } + logMessage(LOG_KERN|priority, log_buffer); + } + +} + extern int syslogd_main(int argc, char **argv) { - int pid; + int pid, klogd_pid; int doFork = TRUE; + char **argv1=argv; - while (--argc > 0 && **(++argv) == '-') { - while (*(++(*argv))) { - switch (**argv) { + while (--argc > 0 && **(++argv1) == '-') { + while (*(++(*argv1))) { + switch (**argv1) { case 'm': if (--argc == 0) { usage(syslogd_usage); } - MarkInterval = atoi(*(++argv))*60; + MarkInterval = atoi(*(++argv1))*60; break; case 'n': doFork = FALSE; @@ -272,7 +368,7 @@ extern int syslogd_main(int argc, char **argv) if (--argc == 0) { usage(syslogd_usage); } - logFilePath = *(++argv); + logFilePath = *(++argv1); break; default: usage(syslogd_usage); @@ -285,11 +381,20 @@ extern int syslogd_main(int argc, char **argv) if ( pid < 0 ) exit( pid); else if ( pid == 0 ) { + strncpy(argv[0], "syslogd",strlen(argv[0])); doSyslogd(); } } else { doSyslogd(); } + + /* Start klogd process */ + klogd_pid = fork(); + if (klogd_pid == 0 ) { + strncpy(argv[0], "klogd", strlen(argv[0])); + doKlogd(); + } + exit( TRUE); } |