aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-06 16:08:04 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-06 16:08:04 +0000
commit7bdf0c82da3713ec2a0f0090ba663c1167d10a67 (patch)
treefa1fef1fcc9071ccaca979724d64e9095a92e351
parent797c96d8ce8765e11510e9dcd4c484ed3ced532c (diff)
downloadbusybox-w32-7bdf0c82da3713ec2a0f0090ba663c1167d10a67.tar.gz
busybox-w32-7bdf0c82da3713ec2a0f0090ba663c1167d10a67.tar.bz2
busybox-w32-7bdf0c82da3713ec2a0f0090ba663c1167d10a67.zip
klogd: make help text more understandable
klogd: by using a register instead of global variable, shrink code a bit function old new delta klogd_main 372 362 -10 packed_usage 24504 24486 -18 text data bss dec hex filename 808464 642 7180 816286 c749e busybox_old 808422 642 7180 816244 c7474 busybox_unstripped
-rw-r--r--include/usage.h4
-rw-r--r--sysklogd/klogd.c33
2 files changed, 19 insertions, 18 deletions
diff --git a/include/usage.h b/include/usage.h
index f9a831e85..44e618222 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -2063,11 +2063,11 @@
2063 "\n -l List all signal names and numbers" \ 2063 "\n -l List all signal names and numbers" \
2064 2064
2065#define klogd_trivial_usage \ 2065#define klogd_trivial_usage \
2066 "[-c n] [-n]" 2066 "[-c N] [-n]"
2067#define klogd_full_usage "\n\n" \ 2067#define klogd_full_usage "\n\n" \
2068 "Kernel logger\n" \ 2068 "Kernel logger\n" \
2069 "\nOptions:" \ 2069 "\nOptions:" \
2070 "\n -c n Set the default log level of console messages to n" \ 2070 "\n -c N Only messages with level < N are printed to console" \
2071 "\n -n Run in foreground" \ 2071 "\n -n Run in foreground" \
2072 2072
2073#define length_trivial_usage \ 2073#define length_trivial_usage \
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index 983a59784..e719001cf 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -21,10 +21,12 @@
21#include <syslog.h> 21#include <syslog.h>
22#include <sys/klog.h> 22#include <sys/klog.h>
23 23
24static void klogd_signal(int sig ATTRIBUTE_UNUSED) 24static void klogd_signal(int sig)
25{ 25{
26 klogctl(7, NULL, 0); 26 /* FYI: cmd 7 is equivalent to setting console_loglevel to 7
27 klogctl(0, NULL, 0); 27 * via klogctl(8, NULL, 7). */
28 klogctl(7, NULL, 0); /* "7 -- Enable printk's to console" */
29 klogctl(0, NULL, 0); /* "0 -- Close the log. Currently a NOP" */
28 syslog(LOG_NOTICE, "klogd: exiting"); 30 syslog(LOG_NOTICE, "klogd: exiting");
29 kill_myself_with_sig(sig); 31 kill_myself_with_sig(sig);
30} 32}
@@ -39,35 +41,33 @@ enum {
39int klogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 41int klogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
40int klogd_main(int argc ATTRIBUTE_UNUSED, char **argv) 42int klogd_main(int argc ATTRIBUTE_UNUSED, char **argv)
41{ 43{
42 int i = i; /* silence gcc */ 44 int i = 0;
43 char *start; 45 char *start;
46 int opt;
44 47
45 /* do normal option parsing */ 48 opt = getopt32(argv, "c:n", &start);
46 getopt32(argv, "c:n", &start); 49 if (opt & OPT_LEVEL) {
47
48 if (option_mask32 & OPT_LEVEL) {
49 /* Valid levels are between 1 and 8 */ 50 /* Valid levels are between 1 and 8 */
50 i = xatoul_range(start, 1, 8); 51 i = xatou_range(start, 1, 8);
51 } 52 }
52 53 if (!(opt & OPT_FOREGROUND)) {
53 if (!(option_mask32 & OPT_FOREGROUND)) {
54 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); 54 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
55 } 55 }
56 56
57 openlog("kernel", 0, LOG_KERN); 57 openlog("kernel", 0, LOG_KERN);
58 58
59 /* Set up sig handlers */
60 bb_signals(0 59 bb_signals(0
61 + (1 << SIGINT) 60 + (1 << SIGINT)
62 + (1 << SIGTERM) 61 + (1 << SIGTERM)
63 , klogd_signal); 62 , klogd_signal);
64 signal(SIGHUP, SIG_IGN); 63 signal(SIGHUP, SIG_IGN);
65 64
66 /* "Open the log. Currently a NOP." */ 65 /* "Open the log. Currently a NOP" */
67 klogctl(1, NULL, 0); 66 klogctl(1, NULL, 0);
68 67
69 /* Set level of kernel console messaging. */ 68 /* "printk() prints a message on the console only if it has a loglevel
70 if (option_mask32 & OPT_LEVEL) 69 * less than console_loglevel". Here we set console_loglevel = i. */
70 if (i)
71 klogctl(8, NULL, i); 71 klogctl(8, NULL, i);
72 72
73 syslog(LOG_NOTICE, "klogd started: %s", bb_banner); 73 syslog(LOG_NOTICE, "klogd started: %s", bb_banner);
@@ -80,11 +80,12 @@ int klogd_main(int argc ATTRIBUTE_UNUSED, char **argv)
80 int n; 80 int n;
81 int priority; 81 int priority;
82 82
83 /* "2 -- Read from the log." */
83 n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1); 84 n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1);
84 if (n < 0) { 85 if (n < 0) {
85 if (errno == EINTR) 86 if (errno == EINTR)
86 continue; 87 continue;
87 syslog(LOG_ERR, "klogd: error from klogctl(2): %d - %m", 88 syslog(LOG_ERR, "klogd: error %d in klogctl(2): %m",
88 errno); 89 errno);
89 break; 90 break;
90 } 91 }