| === modified file 'init/main.c' |
| --- init/main.c 2010-12-13 18:15:24 +0000 |
| +++ init/main.c 2011-02-07 22:08:27 +0000 |
| @@ -61,6 +61,7 @@ |
| |
| /* Prototypes for static functions */ |
| #ifndef DEBUG |
| +static int logger_kmsg (NihLogLevel priority, const char *message); |
| static void crash_handler (int signum); |
| static void cad_handler (void *data, NihSignal *signal); |
| static void kbd_handler (void *data, NihSignal *signal); |
| @@ -314,10 +315,10 @@ |
| |
| #ifndef DEBUG |
| /* Now that the startup is complete, send all further logging output |
| - * to syslog instead of to the console. |
| + * to kmsg instead of to the console. |
| */ |
| - openlog (program_name, LOG_CONS, LOG_DAEMON); |
| - nih_log_set_logger (nih_logger_syslog); |
| + nih_log_set_priority (NIH_LOG_INFO); |
| + nih_log_set_logger (logger_kmsg); |
| #endif /* DEBUG */ |
| |
| |
| @@ -347,6 +348,67 @@ |
| |
| #ifndef DEBUG |
| /** |
| + * logger_kmsg: |
| + * @priority: priority of message being logged, |
| + * @message: message to log. |
| + * |
| + * Outputs the @message to the kernel log message socket prefixed with an |
| + * appropriate tag based on @priority, the program name and terminated with |
| + * a new line. |
| + * |
| + * Returns: zero on success, negative value on error. |
| + **/ |
| +static int |
| +logger_kmsg (NihLogLevel priority, |
| + const char *message) |
| +{ |
| + int tag; |
| + FILE *kmsg; |
| + |
| + nih_assert (message != NULL); |
| + |
| + switch (priority) { |
| + case NIH_LOG_DEBUG: |
| + tag = '7'; |
| + break; |
| + case NIH_LOG_INFO: |
| + tag = '6'; |
| + break; |
| + case NIH_LOG_MESSAGE: |
| + tag = '5'; |
| + break; |
| + case NIH_LOG_WARN: |
| + tag = '4'; |
| + break; |
| + case NIH_LOG_ERROR: |
| + tag = '3'; |
| + break; |
| + case NIH_LOG_FATAL: |
| + tag = '2'; |
| + break; |
| + default: |
| + tag = 'd'; |
| + } |
| + |
| + kmsg = fopen ("/dev/kmsg", "w"); |
| + if (! kmsg) |
| + return -1; |
| + |
| + if (fprintf (kmsg, "<%c>%s: %s\n", tag, program_name, message) < 0) { |
| + int saved_errno = errno; |
| + fclose (kmsg); |
| + errno = saved_errno; |
| + return -1; |
| + } |
| + |
| + if (fclose (kmsg) < 0) |
| + return -1; |
| + |
| + return 0; |
| +} |
| + |
| + |
| +/** |
| * crash_handler: |
| * @signum: signal number received. |
| * |
| |