watchdog: WDIOC_SETTIMEOUT accepts seconds, not milliseconds
klogd: handle many lines at once, by Steve Bennett (steveb AT workware.net.au)
This commit is contained in:
parent
c2d5a27b62
commit
93d0776a96
@ -55,6 +55,8 @@ int watchdog_main(int argc, char **argv)
|
|||||||
/* Use known fd # - avoid needing global 'int fd' */
|
/* Use known fd # - avoid needing global 'int fd' */
|
||||||
xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
|
xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
|
||||||
|
|
||||||
|
/* WDIOC_SETTIMEOUT takes seconds, not milliseconds */
|
||||||
|
htimer_duration = htimer_duration / 1000;
|
||||||
ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration);
|
ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration);
|
||||||
#if 0
|
#if 0
|
||||||
ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration);
|
ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration);
|
||||||
|
@ -44,6 +44,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
char *start;
|
char *start;
|
||||||
int opt;
|
int opt;
|
||||||
|
int used = 0;
|
||||||
|
|
||||||
opt = getopt32(argv, "c:n", &start);
|
opt = getopt32(argv, "c:n", &start);
|
||||||
if (opt & OPT_LEVEL) {
|
if (opt & OPT_LEVEL) {
|
||||||
@ -72,16 +73,15 @@ int klogd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
syslog(LOG_NOTICE, "klogd started: %s", bb_banner);
|
syslog(LOG_NOTICE, "klogd started: %s", bb_banner);
|
||||||
|
|
||||||
/* Note: this code does not detect incomplete messages
|
/* Initially null terminate the buffer in case of a very long line */
|
||||||
* (messages not ending with '\n' or just when kernel
|
log_buffer[KLOGD_LOGBUF_SIZE - 1] = '\0';
|
||||||
* generates too many messages for us to keep up)
|
|
||||||
* and will split them in two separate lines */
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int n;
|
int n;
|
||||||
int priority;
|
int priority;
|
||||||
|
|
||||||
/* "2 -- Read from the log." */
|
/* "2 -- Read from the log." */
|
||||||
n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1);
|
n = klogctl(2, log_buffer + used, KLOGD_LOGBUF_SIZE-1 - used);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
@ -89,32 +89,47 @@ int klogd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
errno);
|
errno);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log_buffer[n] = '\n';
|
|
||||||
i = 0;
|
/* klogctl buffer parsing modelled after code in dmesg.c */
|
||||||
while (i < n) {
|
start = &log_buffer[0];
|
||||||
priority = LOG_INFO;
|
|
||||||
start = &log_buffer[i];
|
/* Process each newline-terminated line in the buffer */
|
||||||
if (log_buffer[i] == '<') {
|
while (1) {
|
||||||
i++;
|
char *newline = strchr(start, '\n');
|
||||||
// kernel never ganerates multi-digit prios
|
|
||||||
//priority = 0;
|
if (!newline) {
|
||||||
//while (log_buffer[i] >= '0' && log_buffer[i] <= '9') {
|
/* This line is incomplete... */
|
||||||
// priority = priority * 10 + (log_buffer[i] - '0');
|
if (start != log_buffer) {
|
||||||
// i++;
|
/* move it to the front of the buffer */
|
||||||
//}
|
strcpy(log_buffer, start);
|
||||||
if (isdigit(log_buffer[i])) {
|
/* don't log it yet */
|
||||||
priority = (log_buffer[i] - '0');
|
used = strlen(log_buffer);
|
||||||
i++;
|
break;
|
||||||
}
|
}
|
||||||
if (log_buffer[i] == '>')
|
/* ...but buffer is full, so log it anyway */
|
||||||
i++;
|
used = 0;
|
||||||
start = &log_buffer[i];
|
} else {
|
||||||
|
*newline++ = '\0';
|
||||||
}
|
}
|
||||||
while (log_buffer[i] != '\n')
|
|
||||||
i++;
|
/* Extract the priority */
|
||||||
log_buffer[i] = '\0';
|
priority = LOG_INFO;
|
||||||
syslog(priority, "%s", start);
|
if (*start == '<') {
|
||||||
i++;
|
start++;
|
||||||
|
if (*start) {
|
||||||
|
/* kernel never generates multi-digit prios */
|
||||||
|
priority = (*start - '0');
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
if (*start == '>') {
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (*start)
|
||||||
|
syslog(priority, "%s", start);
|
||||||
|
if (!newline)
|
||||||
|
break;
|
||||||
|
start = newline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user