Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (17 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/sysklogd/klogd.c

    r821 r1765  
    1818 */
    1919
    20 #include "busybox.h"
    21 #include <stdio.h>
    22 #include <stdlib.h>
    23 #include <signal.h>     /* for our signal() handlers */
    24 #include <string.h>     /* strncpy() */
    25 #include <errno.h>      /* errno and friends */
    26 #include <unistd.h>
    27 #include <ctype.h>
     20#include "libbb.h"
    2821#include <sys/syslog.h>
    2922#include <sys/klog.h>
     
    3326    klogctl(7, NULL, 0);
    3427    klogctl(0, 0, 0);
    35     /* logMessage(0, "Kernel log daemon exiting."); */
    36     syslog(LOG_NOTICE, "Kernel log daemon exiting.");
     28    syslog(LOG_NOTICE, "Kernel log daemon exiting");
    3729    exit(EXIT_SUCCESS);
    3830}
     
    4133#define OPT_FOREGROUND   2
    4234
    43 #define KLOGD_LOGBUF_SIZE 4096
     35#define KLOGD_LOGBUF_SIZE BUFSIZ
     36#define log_buffer bb_common_bufsiz1
    4437
     38int klogd_main(int argc, char **argv);
    4539int klogd_main(int argc, char **argv)
    4640{
    47     RESERVE_CONFIG_BUFFER(log_buffer, KLOGD_LOGBUF_SIZE);
    48     int console_log_level = -1;
    49     int priority = LOG_INFO;
    50     int i, n, lastc;
     41    int i = i; /* silence gcc */
    5142    char *start;
    5243
     44    /* do normal option parsing */
     45    getopt32(argv, "c:n", &start);
    5346
    54     {
    55         unsigned long opt;
     47    if (option_mask32 & OPT_LEVEL) {
     48        /* Valid levels are between 1 and 8 */
     49        i = xatoul_range(start, 1, 8);
     50    }
    5651
    57         /* do normal option parsing */
    58         opt = bb_getopt_ulflags(argc, argv, "c:n", &start);
    59 
    60         if (opt & OPT_LEVEL) {
    61             /* Valid levels are between 1 and 8 */
    62             console_log_level = bb_xgetlarg(start, 10, 1, 8);
    63         }
    64 
    65         if (!(opt & OPT_FOREGROUND)) {
    66 #ifdef BB_NOMMU
    67             vfork_daemon_rexec(0, 1, argc, argv, "-n");
    68 #else
    69             bb_xdaemon(0, 1);
    70 #endif
    71         }
     52    if (!(option_mask32 & OPT_FOREGROUND)) {
     53        bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
    7254    }
    7355
     
    8365    klogctl(1, NULL, 0);
    8466
    85     /* Set level of kernel console messaging.. */
    86     if (console_log_level != -1)
    87         klogctl(8, NULL, console_log_level);
     67    /* Set level of kernel console messaging. */
     68    if (option_mask32 & OPT_LEVEL)
     69        klogctl(8, NULL, i);
    8870
    89     syslog(LOG_NOTICE, "klogd started: %s", BB_BANNER);
     71    syslog(LOG_NOTICE, "klogd started: %s", bb_banner);
    9072
     73    /* Note: this code does not detect incomplete messages
     74     * (messages not ending with '\n' or just when kernel
     75     * generates too many messages for us to keep up)
     76     * and will split them in two separate lines */
    9177    while (1) {
    92         /* Use kernel syscalls */
    93         memset(log_buffer, '\0', KLOGD_LOGBUF_SIZE);
    94         n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE);
     78        int n;
     79        int priority;
     80
     81        n = klogctl(2, log_buffer, KLOGD_LOGBUF_SIZE - 1);
    9582        if (n < 0) {
    9683            if (errno == EINTR)
    9784                continue;
    98             syslog(LOG_ERR, "klogd: Error from sys_sycall: %d - %m.\n",
    99                    errno);
    100             exit(EXIT_FAILURE);
     85            syslog(LOG_ERR, "klogd: error from klogctl(2): %d - %m",
     86                    errno);
     87            break;
    10188        }
    102 
    103         /* klogctl buffer parsing modelled after code in dmesg.c */
    104         start = &log_buffer[0];
    105         lastc = '\0';
    106         for (i = 0; i < n; i++) {
    107             if (lastc == '\0' && log_buffer[i] == '<') {
    108                 priority = 0;
     89        log_buffer[n] = '\n';
     90        i = 0;
     91        while (i < n) {
     92            priority = LOG_INFO;
     93            start = &log_buffer[i];
     94            if (log_buffer[i] == '<') {
    10995                i++;
    110                 while (log_buffer[i] >= '0' && log_buffer[i] <= '9') {
    111                     priority = priority * 10 + (log_buffer[i] - '0');
     96                // kernel never ganerates multi-digit prios
     97                //priority = 0;
     98                //while (log_buffer[i] >= '0' && log_buffer[i] <= '9') {
     99                //  priority = priority * 10 + (log_buffer[i] - '0');
     100                //  i++;
     101                //}
     102                if (isdigit(log_buffer[i])) {
     103                    priority = (log_buffer[i] - '0');
    112104                    i++;
    113105                }
     
    116108                start = &log_buffer[i];
    117109            }
    118             if (log_buffer[i] == '\n') {
    119                 log_buffer[i] = '\0';   /* zero terminate this message */
    120                 syslog(priority, "%s", start);
    121                 start = &log_buffer[i + 1];
    122                 priority = LOG_INFO;
    123             }
    124             lastc = log_buffer[i];
     110            while (log_buffer[i] != '\n')
     111                i++;
     112            log_buffer[i] = '\0';
     113            syslog(priority, "%s", start);
     114            i++;
    125115        }
    126116    }
    127     if (ENABLE_FEATURE_CLEAN_UP)
    128         RELEASE_CONFIG_BUFFER(log_buffer);
    129117
    130     return EXIT_SUCCESS;
     118    return EXIT_FAILURE;
    131119}
Note: See TracChangeset for help on using the changeset viewer.