aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/watchdog.c2
-rw-r--r--sysklogd/klogd.c71
2 files changed, 45 insertions, 28 deletions
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index 9bcd4b874..75a399f24 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -55,6 +55,8 @@ int watchdog_main(int argc, char **argv)
55 /* Use known fd # - avoid needing global 'int fd' */ 55 /* Use known fd # - avoid needing global 'int fd' */
56 xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3); 56 xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
57 57
58 /* WDIOC_SETTIMEOUT takes seconds, not milliseconds */
59 htimer_duration = htimer_duration / 1000;
58 ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration); 60 ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration);
59#if 0 61#if 0
60 ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration); 62 ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration);
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index c4bbf1558..723ca8067 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -44,6 +44,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv)
44 int i = 0; 44 int i = 0;
45 char *start; 45 char *start;
46 int opt; 46 int opt;
47 int used = 0;
47 48
48 opt = getopt32(argv, "c:n", &start); 49 opt = getopt32(argv, "c:n", &start);
49 if (opt & OPT_LEVEL) { 50 if (opt & OPT_LEVEL) {
@@ -72,16 +73,15 @@ int klogd_main(int argc UNUSED_PARAM, char **argv)
72 73
73 syslog(LOG_NOTICE, "klogd started: %s", bb_banner); 74 syslog(LOG_NOTICE, "klogd started: %s", bb_banner);
74 75
75 /* Note: this code does not detect incomplete messages 76 /* Initially null terminate the buffer in case of a very long line */
76 * (messages not ending with '\n' or just when kernel 77 log_buffer[KLOGD_LOGBUF_SIZE - 1] = '\0';
77 * generates too many messages for us to keep up) 78
78 * and will split them in two separate lines */
79 while (1) { 79 while (1) {
80 int n; 80 int n;
81 int priority; 81 int priority;
82 82
83 /* "2 -- Read from the log." */ 83 /* "2 -- Read from the log." */
84 n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1); 84 n = klogctl(2, log_buffer + used, KLOGD_LOGBUF_SIZE-1 - used);
85 if (n < 0) { 85 if (n < 0) {
86 if (errno == EINTR) 86 if (errno == EINTR)
87 continue; 87 continue;
@@ -89,32 +89,47 @@ int klogd_main(int argc UNUSED_PARAM, char **argv)
89 errno); 89 errno);
90 break; 90 break;
91 } 91 }
92 log_buffer[n] = '\n'; 92
93 i = 0; 93 /* klogctl buffer parsing modelled after code in dmesg.c */
94 while (i < n) { 94 start = &log_buffer[0];
95
96 /* Process each newline-terminated line in the buffer */
97 while (1) {
98 char *newline = strchr(start, '\n');
99
100 if (!newline) {
101 /* This line is incomplete... */
102 if (start != log_buffer) {
103 /* move it to the front of the buffer */
104 strcpy(log_buffer, start);
105 /* don't log it yet */
106 used = strlen(log_buffer);
107 break;
108 }
109 /* ...but buffer is full, so log it anyway */
110 used = 0;
111 } else {
112 *newline++ = '\0';
113 }
114
115 /* Extract the priority */
95 priority = LOG_INFO; 116 priority = LOG_INFO;
96 start = &log_buffer[i]; 117 if (*start == '<') {
97 if (log_buffer[i] == '<') { 118 start++;
98 i++; 119 if (*start) {
99 // kernel never ganerates multi-digit prios 120 /* kernel never generates multi-digit prios */
100 //priority = 0; 121 priority = (*start - '0');
101 //while (log_buffer[i] >= '0' && log_buffer[i] <= '9') { 122 start++;
102 // priority = priority * 10 + (log_buffer[i] - '0'); 123 }
103 // i++; 124 if (*start == '>') {
104 //} 125 start++;
105 if (isdigit(log_buffer[i])) {
106 priority = (log_buffer[i] - '0');
107 i++;
108 } 126 }
109 if (log_buffer[i] == '>')
110 i++;
111 start = &log_buffer[i];
112 } 127 }
113 while (log_buffer[i] != '\n') 128 if (*start)
114 i++; 129 syslog(priority, "%s", start);
115 log_buffer[i] = '\0'; 130 if (!newline)
116 syslog(priority, "%s", start); 131 break;
117 i++; 132 start = newline;
118 } 133 }
119 } 134 }
120 135