klogd: small optimizations
(btw, I looked into syslogd... that's frightening!)
This commit is contained in:
parent
b8429fb1f4
commit
e428e9d43b
@ -25,8 +25,7 @@ static void klogd_signal(int sig ATTRIBUTE_UNUSED)
|
|||||||
{
|
{
|
||||||
klogctl(7, NULL, 0);
|
klogctl(7, NULL, 0);
|
||||||
klogctl(0, 0, 0);
|
klogctl(0, 0, 0);
|
||||||
/* logMessage(0, "Kernel log daemon exiting."); */
|
syslog(LOG_NOTICE, "Kernel log daemon exiting");
|
||||||
syslog(LOG_NOTICE, "Kernel log daemon exiting.");
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,30 +37,26 @@ static void klogd_signal(int sig ATTRIBUTE_UNUSED)
|
|||||||
int klogd_main(int argc, char **argv)
|
int klogd_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
RESERVE_CONFIG_BUFFER(log_buffer, KLOGD_LOGBUF_SIZE);
|
RESERVE_CONFIG_BUFFER(log_buffer, KLOGD_LOGBUF_SIZE);
|
||||||
int console_log_level = -1;
|
int console_log_level = console_log_level; /* for gcc */
|
||||||
int priority = LOG_INFO;
|
int priority = LOG_INFO;
|
||||||
int i, n, lastc;
|
int i, n, lastc;
|
||||||
char *start;
|
char *start;
|
||||||
|
|
||||||
{
|
|
||||||
unsigned opt;
|
|
||||||
|
|
||||||
/* do normal option parsing */
|
/* do normal option parsing */
|
||||||
opt = getopt32(argc, argv, "c:n", &start);
|
n = getopt32(argc, argv, "c:n", &start);
|
||||||
|
|
||||||
if (opt & OPT_LEVEL) {
|
if (n & OPT_LEVEL) {
|
||||||
/* Valid levels are between 1 and 8 */
|
/* Valid levels are between 1 and 8 */
|
||||||
console_log_level = xatoul_range(start, 1, 8);
|
console_log_level = xatoul_range(start, 1, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(opt & OPT_FOREGROUND)) {
|
if (!(n & OPT_FOREGROUND)) {
|
||||||
#ifdef BB_NOMMU
|
#ifdef BB_NOMMU
|
||||||
vfork_daemon_rexec(0, 1, argc, argv, "-n");
|
vfork_daemon_rexec(0, 1, argc, argv, "-n");
|
||||||
#else
|
#else
|
||||||
xdaemon(0, 1);
|
xdaemon(0, 1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
openlog("kernel", 0, LOG_KERN);
|
openlog("kernel", 0, LOG_KERN);
|
||||||
|
|
||||||
@ -75,7 +70,7 @@ int klogd_main(int argc, char **argv)
|
|||||||
klogctl(1, NULL, 0);
|
klogctl(1, NULL, 0);
|
||||||
|
|
||||||
/* Set level of kernel console messaging.. */
|
/* Set level of kernel console messaging.. */
|
||||||
if (console_log_level != -1)
|
if (n & OPT_LEVEL)
|
||||||
klogctl(8, NULL, console_log_level);
|
klogctl(8, NULL, console_log_level);
|
||||||
|
|
||||||
syslog(LOG_NOTICE, "klogd started: %s", BB_BANNER);
|
syslog(LOG_NOTICE, "klogd started: %s", BB_BANNER);
|
||||||
@ -83,13 +78,14 @@ int klogd_main(int argc, char **argv)
|
|||||||
while (1) {
|
while (1) {
|
||||||
/* Use kernel syscalls */
|
/* Use kernel syscalls */
|
||||||
memset(log_buffer, '\0', KLOGD_LOGBUF_SIZE);
|
memset(log_buffer, '\0', KLOGD_LOGBUF_SIZE);
|
||||||
n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE);
|
/* It will be null-terminted */
|
||||||
|
n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
syslog(LOG_ERR, "klogd: Error from sys_sycall: %d - %m.\n",
|
syslog(LOG_ERR, "klogd: error from klogctl(2): %d - %m",
|
||||||
errno);
|
errno);
|
||||||
exit(EXIT_FAILURE);
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* klogctl buffer parsing modelled after code in dmesg.c */
|
/* klogctl buffer parsing modelled after code in dmesg.c */
|
||||||
@ -97,10 +93,15 @@ int klogd_main(int argc, char **argv)
|
|||||||
lastc = '\0';
|
lastc = '\0';
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (lastc == '\0' && log_buffer[i] == '<') {
|
if (lastc == '\0' && log_buffer[i] == '<') {
|
||||||
priority = 0;
|
|
||||||
i++;
|
i++;
|
||||||
while (log_buffer[i] >= '0' && log_buffer[i] <= '9') {
|
// kernel never ganerates multi-digit prios
|
||||||
priority = priority * 10 + (log_buffer[i] - '0');
|
//priority = 0;
|
||||||
|
//while (log_buffer[i] >= '0' && log_buffer[i] <= '9') {
|
||||||
|
// priority = priority * 10 + (log_buffer[i] - '0');
|
||||||
|
// i++;
|
||||||
|
//}
|
||||||
|
if (isdigit(log_buffer[i])) {
|
||||||
|
priority = (log_buffer[i] - '0');
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (log_buffer[i] == '>')
|
if (log_buffer[i] == '>')
|
||||||
@ -119,5 +120,5 @@ int klogd_main(int argc, char **argv)
|
|||||||
if (ENABLE_FEATURE_CLEAN_UP)
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
RELEASE_CONFIG_BUFFER(log_buffer);
|
RELEASE_CONFIG_BUFFER(log_buffer);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user