diff options
Diffstat (limited to 'sysklogd')
-rw-r--r-- | sysklogd/Config.src | 16 | ||||
-rw-r--r-- | sysklogd/klogd.c | 10 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 82 |
3 files changed, 93 insertions, 15 deletions
diff --git a/sysklogd/Config.src b/sysklogd/Config.src index b7a494eff..fcf993054 100644 --- a/sysklogd/Config.src +++ b/sysklogd/Config.src | |||
@@ -113,6 +113,19 @@ config FEATURE_LOGREAD_REDUCED_LOCKING | |||
113 | from circular buffer, minimizing semaphore | 113 | from circular buffer, minimizing semaphore |
114 | contention at some minor memory expense. | 114 | contention at some minor memory expense. |
115 | 115 | ||
116 | config FEATURE_KMSG_SYSLOG | ||
117 | bool "Linux kernel printk buffer support" | ||
118 | default y | ||
119 | depends on SYSLOGD | ||
120 | select PLATFORM_LINUX | ||
121 | help | ||
122 | When you enable this feature, the syslogd utility will | ||
123 | write system log message to the Linux kernel's printk buffer. | ||
124 | This can be used as a smaller alternative to the syslogd IPC | ||
125 | support, as klogd and logread aren't needed. | ||
126 | |||
127 | NOTICE: Syslog facilities in log entries needs kernel 3.5+. | ||
128 | |||
116 | config KLOGD | 129 | config KLOGD |
117 | bool "klogd" | 130 | bool "klogd" |
118 | default y | 131 | default y |
@@ -123,6 +136,9 @@ config KLOGD | |||
123 | you wish to record the messages produced by the kernel, | 136 | you wish to record the messages produced by the kernel, |
124 | you should enable this option. | 137 | you should enable this option. |
125 | 138 | ||
139 | comment "klogd should not be used together with syslog to kernel printk buffer" | ||
140 | depends on KLOGD && FEATURE_KMSG_SYSLOG | ||
141 | |||
126 | config FEATURE_KLOGD_KLOGCTL | 142 | config FEATURE_KLOGD_KLOGCTL |
127 | bool "Use the klogctl() interface" | 143 | bool "Use the klogctl() interface" |
128 | default y | 144 | default y |
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index efa0e537a..432ded153 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -195,6 +195,8 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
195 | 195 | ||
196 | syslog(LOG_NOTICE, "klogd started: %s", bb_banner); | 196 | syslog(LOG_NOTICE, "klogd started: %s", bb_banner); |
197 | 197 | ||
198 | write_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); | ||
199 | |||
198 | used = 0; | 200 | used = 0; |
199 | while (!bb_got_signal) { | 201 | while (!bb_got_signal) { |
200 | int n; | 202 | int n; |
@@ -238,11 +240,8 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
238 | priority = LOG_INFO; | 240 | priority = LOG_INFO; |
239 | if (*start == '<') { | 241 | if (*start == '<') { |
240 | start++; | 242 | start++; |
241 | if (*start) { | 243 | if (*start) |
242 | /* kernel never generates multi-digit prios */ | 244 | priority = strtoul(start, &start, 10); |
243 | priority = (*start - '0'); | ||
244 | start++; | ||
245 | } | ||
246 | if (*start == '>') | 245 | if (*start == '>') |
247 | start++; | 246 | start++; |
248 | } | 247 | } |
@@ -258,6 +257,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
258 | 257 | ||
259 | klogd_close(); | 258 | klogd_close(); |
260 | syslog(LOG_NOTICE, "klogd: exiting"); | 259 | syslog(LOG_NOTICE, "klogd: exiting"); |
260 | remove_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); | ||
261 | if (bb_got_signal) | 261 | if (bb_got_signal) |
262 | kill_myself_with_sig(bb_got_signal); | 262 | kill_myself_with_sig(bb_got_signal); |
263 | return EXIT_FAILURE; | 263 | return EXIT_FAILURE; |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index fc380d9f9..3fe3f5348 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -43,6 +43,9 @@ | |||
43 | //usage: "\n -f FILE Use FILE as config (default:/etc/syslog.conf)" | 43 | //usage: "\n -f FILE Use FILE as config (default:/etc/syslog.conf)" |
44 | //usage: ) | 44 | //usage: ) |
45 | /* //usage: "\n -m MIN Minutes between MARK lines (default:20, 0=off)" */ | 45 | /* //usage: "\n -m MIN Minutes between MARK lines (default:20, 0=off)" */ |
46 | //usage: IF_FEATURE_KMSG_SYSLOG( | ||
47 | //usage: "\n -K Log to kernel printk buffer (use dmesg to read it)" | ||
48 | //usage: ) | ||
46 | //usage: | 49 | //usage: |
47 | //usage:#define syslogd_example_usage | 50 | //usage:#define syslogd_example_usage |
48 | //usage: "$ syslogd -R masterlog:514\n" | 51 | //usage: "$ syslogd -R masterlog:514\n" |
@@ -140,6 +143,10 @@ IF_FEATURE_IPC_SYSLOG( \ | |||
140 | ) \ | 143 | ) \ |
141 | IF_FEATURE_SYSLOGD_CFG( \ | 144 | IF_FEATURE_SYSLOGD_CFG( \ |
142 | logRule_t *log_rules; \ | 145 | logRule_t *log_rules; \ |
146 | ) \ | ||
147 | IF_FEATURE_KMSG_SYSLOG( \ | ||
148 | int kmsgfd; \ | ||
149 | int primask; \ | ||
143 | ) | 150 | ) |
144 | 151 | ||
145 | struct init_globals { | 152 | struct init_globals { |
@@ -212,6 +219,7 @@ enum { | |||
212 | IF_FEATURE_IPC_SYSLOG( OPTBIT_circularlog,) // -C | 219 | IF_FEATURE_IPC_SYSLOG( OPTBIT_circularlog,) // -C |
213 | IF_FEATURE_SYSLOGD_DUP( OPTBIT_dup ,) // -D | 220 | IF_FEATURE_SYSLOGD_DUP( OPTBIT_dup ,) // -D |
214 | IF_FEATURE_SYSLOGD_CFG( OPTBIT_cfg ,) // -f | 221 | IF_FEATURE_SYSLOGD_CFG( OPTBIT_cfg ,) // -f |
222 | IF_FEATURE_KMSG_SYSLOG( OPTBIT_kmsg ,) // -K | ||
215 | 223 | ||
216 | OPT_mark = 1 << OPTBIT_mark , | 224 | OPT_mark = 1 << OPTBIT_mark , |
217 | OPT_nofork = 1 << OPTBIT_nofork , | 225 | OPT_nofork = 1 << OPTBIT_nofork , |
@@ -225,6 +233,8 @@ enum { | |||
225 | OPT_circularlog = IF_FEATURE_IPC_SYSLOG( (1 << OPTBIT_circularlog)) + 0, | 233 | OPT_circularlog = IF_FEATURE_IPC_SYSLOG( (1 << OPTBIT_circularlog)) + 0, |
226 | OPT_dup = IF_FEATURE_SYSLOGD_DUP( (1 << OPTBIT_dup )) + 0, | 234 | OPT_dup = IF_FEATURE_SYSLOGD_DUP( (1 << OPTBIT_dup )) + 0, |
227 | OPT_cfg = IF_FEATURE_SYSLOGD_CFG( (1 << OPTBIT_cfg )) + 0, | 235 | OPT_cfg = IF_FEATURE_SYSLOGD_CFG( (1 << OPTBIT_cfg )) + 0, |
236 | OPT_kmsg = IF_FEATURE_KMSG_SYSLOG( (1 << OPTBIT_kmsg )) + 0, | ||
237 | |||
228 | }; | 238 | }; |
229 | #define OPTION_STR "m:nO:l:S" \ | 239 | #define OPTION_STR "m:nO:l:S" \ |
230 | IF_FEATURE_ROTATE_LOGFILE("s:" ) \ | 240 | IF_FEATURE_ROTATE_LOGFILE("s:" ) \ |
@@ -233,7 +243,8 @@ enum { | |||
233 | IF_FEATURE_REMOTE_LOG( "L" ) \ | 243 | IF_FEATURE_REMOTE_LOG( "L" ) \ |
234 | IF_FEATURE_IPC_SYSLOG( "C::") \ | 244 | IF_FEATURE_IPC_SYSLOG( "C::") \ |
235 | IF_FEATURE_SYSLOGD_DUP( "D" ) \ | 245 | IF_FEATURE_SYSLOGD_DUP( "D" ) \ |
236 | IF_FEATURE_SYSLOGD_CFG( "f:" ) | 246 | IF_FEATURE_SYSLOGD_CFG( "f:" ) \ |
247 | IF_FEATURE_KMSG_SYSLOG( "K" ) | ||
237 | #define OPTION_DECL *opt_m, *opt_l \ | 248 | #define OPTION_DECL *opt_m, *opt_l \ |
238 | IF_FEATURE_ROTATE_LOGFILE(,*opt_s) \ | 249 | IF_FEATURE_ROTATE_LOGFILE(,*opt_s) \ |
239 | IF_FEATURE_ROTATE_LOGFILE(,*opt_b) \ | 250 | IF_FEATURE_ROTATE_LOGFILE(,*opt_b) \ |
@@ -242,7 +253,7 @@ enum { | |||
242 | #define OPTION_PARAM &opt_m, &(G.logFile.path), &opt_l \ | 253 | #define OPTION_PARAM &opt_m, &(G.logFile.path), &opt_l \ |
243 | IF_FEATURE_ROTATE_LOGFILE(,&opt_s) \ | 254 | IF_FEATURE_ROTATE_LOGFILE(,&opt_s) \ |
244 | IF_FEATURE_ROTATE_LOGFILE(,&opt_b) \ | 255 | IF_FEATURE_ROTATE_LOGFILE(,&opt_b) \ |
245 | IF_FEATURE_REMOTE_LOG( ,&remoteAddrList) \ | 256 | IF_FEATURE_REMOTE_LOG( ,&remoteAddrList) \ |
246 | IF_FEATURE_IPC_SYSLOG( ,&opt_C) \ | 257 | IF_FEATURE_IPC_SYSLOG( ,&opt_C) \ |
247 | IF_FEATURE_SYSLOGD_CFG( ,&opt_f) | 258 | IF_FEATURE_SYSLOGD_CFG( ,&opt_f) |
248 | 259 | ||
@@ -418,7 +429,9 @@ static void parse_syslogdcfg(const char *file) | |||
418 | return; | 429 | return; |
419 | 430 | ||
420 | cfgerr: | 431 | cfgerr: |
421 | bb_error_msg_and_die("error in '%s' at line %d", file, parser->lineno); | 432 | bb_error_msg_and_die("error in '%s' at line %d", |
433 | file ? file : "/etc/syslog.conf", | ||
434 | parser->lineno); | ||
422 | } | 435 | } |
423 | #endif | 436 | #endif |
424 | 437 | ||
@@ -518,11 +531,49 @@ static void log_to_shmem(const char *msg) | |||
518 | printf("tail:%d\n", G.shbuf->tail); | 531 | printf("tail:%d\n", G.shbuf->tail); |
519 | } | 532 | } |
520 | #else | 533 | #else |
521 | void ipcsyslog_cleanup(void); | 534 | static void ipcsyslog_cleanup(void) {} |
522 | void ipcsyslog_init(void); | 535 | static void ipcsyslog_init(void) {} |
523 | void log_to_shmem(const char *msg); | 536 | void log_to_shmem(const char *msg); |
524 | #endif /* FEATURE_IPC_SYSLOG */ | 537 | #endif /* FEATURE_IPC_SYSLOG */ |
525 | 538 | ||
539 | #if ENABLE_FEATURE_KMSG_SYSLOG | ||
540 | static void kmsg_init(void) | ||
541 | { | ||
542 | G.kmsgfd = xopen("/dev/kmsg", O_WRONLY); | ||
543 | |||
544 | /* | ||
545 | * kernel < 3.5 expects single char printk KERN_* priority prefix, | ||
546 | * from 3.5 onwards the full syslog facility/priority format is supported | ||
547 | */ | ||
548 | if (get_linux_version_code() < KERNEL_VERSION(3,5,0)) | ||
549 | G.primask = LOG_PRIMASK; | ||
550 | else | ||
551 | G.primask = -1; | ||
552 | } | ||
553 | |||
554 | static void kmsg_cleanup(void) | ||
555 | { | ||
556 | if (ENABLE_FEATURE_CLEAN_UP) | ||
557 | close(G.kmsgfd); | ||
558 | } | ||
559 | |||
560 | /* Write message to /dev/kmsg */ | ||
561 | static void log_to_kmsg(int pri, const char *msg) | ||
562 | { | ||
563 | /* | ||
564 | * kernel < 3.5 expects single char printk KERN_* priority prefix, | ||
565 | * from 3.5 onwards the full syslog facility/priority format is supported | ||
566 | */ | ||
567 | pri &= G.primask; | ||
568 | |||
569 | write(G.kmsgfd, G.printbuf, sprintf(G.printbuf, "<%d>%s\n", pri, msg)); | ||
570 | } | ||
571 | #else | ||
572 | static void kmsg_init(void) {} | ||
573 | static void kmsg_cleanup(void) {} | ||
574 | static void log_to_kmsg(int pri UNUSED_PARAM, const char *msg UNUSED_PARAM) {} | ||
575 | #endif /* FEATURE_KMSG_SYSLOG */ | ||
576 | |||
526 | /* Print a message to the log file. */ | 577 | /* Print a message to the log file. */ |
527 | static void log_locally(time_t now, char *msg, logFile_t *log_file) | 578 | static void log_locally(time_t now, char *msg, logFile_t *log_file) |
528 | { | 579 | { |
@@ -657,6 +708,11 @@ static void timestamp_and_log(int pri, char *msg, int len) | |||
657 | } | 708 | } |
658 | timestamp[15] = '\0'; | 709 | timestamp[15] = '\0'; |
659 | 710 | ||
711 | if (option_mask32 & OPT_kmsg) { | ||
712 | log_to_kmsg(pri, msg); | ||
713 | return; | ||
714 | } | ||
715 | |||
660 | if (option_mask32 & OPT_small) | 716 | if (option_mask32 & OPT_small) |
661 | sprintf(G.printbuf, "%s %s\n", timestamp, msg); | 717 | sprintf(G.printbuf, "%s %s\n", timestamp, msg); |
662 | else { | 718 | else { |
@@ -827,9 +883,11 @@ static void do_syslogd(void) | |||
827 | #endif | 883 | #endif |
828 | sock_fd = create_socket(); | 884 | sock_fd = create_socket(); |
829 | 885 | ||
830 | if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) { | 886 | if (option_mask32 & OPT_circularlog) |
831 | ipcsyslog_init(); | 887 | ipcsyslog_init(); |
832 | } | 888 | |
889 | if (option_mask32 & OPT_kmsg) | ||
890 | kmsg_init(); | ||
833 | 891 | ||
834 | timestamp_and_log_internal("syslogd started: BusyBox v" BB_VER); | 892 | timestamp_and_log_internal("syslogd started: BusyBox v" BB_VER); |
835 | 893 | ||
@@ -916,8 +974,10 @@ static void do_syslogd(void) | |||
916 | 974 | ||
917 | timestamp_and_log_internal("syslogd exiting"); | 975 | timestamp_and_log_internal("syslogd exiting"); |
918 | puts("syslogd exiting"); | 976 | puts("syslogd exiting"); |
919 | if (ENABLE_FEATURE_IPC_SYSLOG) | 977 | remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); |
920 | ipcsyslog_cleanup(); | 978 | ipcsyslog_cleanup(); |
979 | if (option_mask32 & OPT_kmsg) | ||
980 | kmsg_cleanup(); | ||
921 | kill_myself_with_sig(bb_got_signal); | 981 | kill_myself_with_sig(bb_got_signal); |
922 | #undef recvbuf | 982 | #undef recvbuf |
923 | } | 983 | } |
@@ -979,8 +1039,10 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv) | |||
979 | if (!(opts & OPT_nofork)) { | 1039 | if (!(opts & OPT_nofork)) { |
980 | bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); | 1040 | bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); |
981 | } | 1041 | } |
1042 | |||
982 | //umask(0); - why?? | 1043 | //umask(0); - why?? |
983 | write_pidfile("/var/run/syslogd.pid"); | 1044 | write_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); |
1045 | |||
984 | do_syslogd(); | 1046 | do_syslogd(); |
985 | /* return EXIT_SUCCESS; */ | 1047 | /* return EXIT_SUCCESS; */ |
986 | } | 1048 | } |