aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-05-31 12:22:13 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-05-31 12:22:13 +0000
commit595159f38cfbf355eb221be337de0e25e12ea7af (patch)
treed3d6fb02a0c5900a1dc7b1df2145345dca4e2f47
parentc418d482baf414ef3f08a95ab99da7091f358b89 (diff)
downloadbusybox-w32-595159f38cfbf355eb221be337de0e25e12ea7af.tar.gz
busybox-w32-595159f38cfbf355eb221be337de0e25e12ea7af.tar.bz2
busybox-w32-595159f38cfbf355eb221be337de0e25e12ea7af.zip
- shrink klogd a bit
text data bss dec hex filename 569 0 0 569 239 sysklogd/klogd.o.orig 537 0 0 537 219 sysklogd/klogd.o
-rw-r--r--sysklogd/klogd.c72
1 files changed, 37 insertions, 35 deletions
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index cd152a570..404e2275d 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -29,7 +29,7 @@
29 29
30#include "busybox.h" 30#include "busybox.h"
31 31
32static void klogd_signal(int sig) 32static void klogd_signal(int sig ATTRIBUTE_UNUSED)
33{ 33{
34 klogctl(7, NULL, 0); 34 klogctl(7, NULL, 0);
35 klogctl(0, 0, 0); 35 klogctl(0, 0, 0);
@@ -38,14 +38,40 @@ static void klogd_signal(int sig)
38 exit(EXIT_SUCCESS); 38 exit(EXIT_SUCCESS);
39} 39}
40 40
41static void doKlogd(const int console_log_level) ATTRIBUTE_NORETURN; 41#define OPT_LEVEL 1
42static void doKlogd(const int console_log_level) 42#define OPT_FOREGROUND 2
43
44#define KLOGD_LOGBUF_SIZE 4096
45
46int klogd_main(int argc, char **argv)
43{ 47{
48 RESERVE_CONFIG_BUFFER(log_buffer, KLOGD_LOGBUF_SIZE);
49 int console_log_level = -1;
44 int priority = LOG_INFO; 50 int priority = LOG_INFO;
45 char log_buffer[4096];
46 int i, n, lastc; 51 int i, n, lastc;
47 char *start; 52 char *start;
48 53
54
55 {
56 unsigned long opt;
57
58 /* do normal option parsing */
59 opt = bb_getopt_ulflags(argc, argv, "c:n", &start);
60
61 if (opt & OPT_LEVEL) {
62 /* Valid levels are between 1 and 8 */
63 console_log_level = bb_xgetlarg(start, 10, 1, 8);
64 }
65
66 if (!(opt & OPT_FOREGROUND)) {
67#ifdef BB_NOMMU
68 vfork_daemon_rexec(0, 1, argc, argv, "-n");
69#else
70 bb_xdaemon(0, 1);
71#endif
72 }
73 }
74
49 openlog("kernel", 0, LOG_KERN); 75 openlog("kernel", 0, LOG_KERN);
50 76
51 /* Set up sig handlers */ 77 /* Set up sig handlers */
@@ -65,12 +91,13 @@ static void doKlogd(const int console_log_level)
65 91
66 while (1) { 92 while (1) {
67 /* Use kernel syscalls */ 93 /* Use kernel syscalls */
68 memset(log_buffer, '\0', sizeof(log_buffer)); 94 memset(log_buffer, '\0', KLOGD_LOGBUF_SIZE);
69 n = klogctl(2, log_buffer, sizeof(log_buffer)); 95 n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE);
70 if (n < 0) { 96 if (n < 0) {
71 if (errno == EINTR) 97 if (errno == EINTR)
72 continue; 98 continue;
73 syslog(LOG_ERR, "klogd: Error return from sys_sycall: %d - %m.\n", errno); 99 syslog(LOG_ERR, "klogd: Error from sys_sycall: %d - %m.\n",
100 errno);
74 exit(EXIT_FAILURE); 101 exit(EXIT_FAILURE);
75 } 102 }
76 103
@@ -81,7 +108,7 @@ static void doKlogd(const int console_log_level)
81 if (lastc == '\0' && log_buffer[i] == '<') { 108 if (lastc == '\0' && log_buffer[i] == '<') {
82 priority = 0; 109 priority = 0;
83 i++; 110 i++;
84 while (isdigit(log_buffer[i])) { 111 while (log_buffer[i] >= '0' && log_buffer[i] <= '9') {
85 priority = priority * 10 + (log_buffer[i] - '0'); 112 priority = priority * 10 + (log_buffer[i] - '0');
86 i++; 113 i++;
87 } 114 }
@@ -98,33 +125,8 @@ static void doKlogd(const int console_log_level)
98 lastc = log_buffer[i]; 125 lastc = log_buffer[i];
99 } 126 }
100 } 127 }
101} 128 if (ENABLE_FEATURE_CLEAN_UP)
102 129 RELEASE_CONFIG_BUFFER(log_buffer);
103#define OPT_LEVEL 1
104#define OPT_FOREGROUND 2
105
106int klogd_main(int argc, char **argv)
107{
108 unsigned long opt;
109 char *c_arg;
110 int console_log_level = -1;
111
112 /* do normal option parsing */
113 opt = bb_getopt_ulflags (argc, argv, "c:n", &c_arg);
114
115 if (opt & OPT_LEVEL) {
116 /* Valid levels are between 1 and 8 */
117 console_log_level = bb_xgetlarg(c_arg, 10, 1, 8);
118 }
119
120 if (!(opt & OPT_FOREGROUND)) {
121#ifdef BB_NOMMU
122 vfork_daemon_rexec(0, 1, argc, argv, "-n");
123#else
124 bb_xdaemon(0, 1);
125#endif
126 }
127 doKlogd(console_log_level);
128 130
129 return EXIT_SUCCESS; 131 return EXIT_SUCCESS;
130} 132}