1 /* vi: set sw=4 ts=4: */
3 * Mini klogd implementation for busybox
5 * Copyright (C) 2001 by Gennady Feldman <gfeldman@gena01.com>.
6 * Changes: Made this a standalone busybox module which uses standalone
7 * syslog() client interface.
9 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
11 * Copyright (C) 2000 by Karl M. Hegbloom <karlheg@debian.org>
13 * "circular buffer" Copyright (C) 2000 by Gennady Feldman <gfeldman@gena01.com>
15 * Maintainer: Gennady Feldman <gfeldman@gena01.com> as of Mar 12, 2001
17 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
24 static void klogd_signal(int sig ATTRIBUTE_UNUSED)
28 syslog(LOG_NOTICE, "klogd: exiting");
32 #define log_buffer bb_common_bufsiz1
34 KLOGD_LOGBUF_SIZE = sizeof(log_buffer),
36 OPT_FOREGROUND = (1 << 1),
39 int klogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
40 int klogd_main(int argc, char **argv)
42 int i = i; /* silence gcc */
45 /* do normal option parsing */
46 getopt32(argv, "c:n", &start);
48 if (option_mask32 & OPT_LEVEL) {
49 /* Valid levels are between 1 and 8 */
50 i = xatoul_range(start, 1, 8);
53 if (!(option_mask32 & OPT_FOREGROUND)) {
54 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
57 openlog("kernel", 0, LOG_KERN);
59 /* Set up sig handlers */
64 signal(SIGHUP, SIG_IGN);
66 /* "Open the log. Currently a NOP." */
69 /* Set level of kernel console messaging. */
70 if (option_mask32 & OPT_LEVEL)
73 syslog(LOG_NOTICE, "klogd started: %s", bb_banner);
75 /* Note: this code does not detect incomplete messages
76 * (messages not ending with '\n' or just when kernel
77 * generates too many messages for us to keep up)
78 * and will split them in two separate lines */
83 n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1);
87 syslog(LOG_ERR, "klogd: error from klogctl(2): %d - %m",
95 start = &log_buffer[i];
96 if (log_buffer[i] == '<') {
98 // kernel never ganerates multi-digit prios
100 //while (log_buffer[i] >= '0' && log_buffer[i] <= '9') {
101 // priority = priority * 10 + (log_buffer[i] - '0');
104 if (isdigit(log_buffer[i])) {
105 priority = (log_buffer[i] - '0');
108 if (log_buffer[i] == '>')
110 start = &log_buffer[i];
112 while (log_buffer[i] != '\n')
114 log_buffer[i] = '\0';
115 syslog(priority, "%s", start);