Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/util-linux/dmesg.c

    r1765 r2725  
    55 *
    66 * Copyright 2006 Rob Landley <rob@landley.net>
    7  * Copyright 2006 Bernhard Fischer <rep.nop@aon.at>
     7 * Copyright 2006 Bernhard Reutner-Fischer <rep.nop@aon.at>
    88 *
    9  * Licensed under GPLv2, see file LICENSE in this tarball for details.
     9 * Licensed under GPLv2, see file LICENSE in this source tree.
    1010 */
    11 
    1211#include <sys/klog.h>
    1312#include "libbb.h"
    1413
    15 int dmesg_main(int argc, char **argv);
    16 int dmesg_main(int argc, char **argv)
     14int dmesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     15int dmesg_main(int argc UNUSED_PARAM, char **argv)
    1716{
    18     char *size, *level;
    19     int flags = getopt32(argv, "cs:n:", &size, &level);
     17    int len, level;
     18    char *buf;
     19    unsigned opts;
     20    enum {
     21        OPT_c = 1 << 0,
     22        OPT_s = 1 << 1,
     23        OPT_n = 1 << 2
     24    };
    2025
    21     if (flags & 4) {
    22         if (klogctl(8, NULL, xatoul_range(level, 0, 10)))
     26    opt_complementary = "s+:n+"; /* numeric */
     27    opts = getopt32(argv, "cs:n:", &len, &level);
     28    if (opts & OPT_n) {
     29        if (klogctl(8, NULL, (long) level))
    2330            bb_perror_msg_and_die("klogctl");
    24     } else {
    25         int len;
    26         char *buf;
    27 
    28         len = (flags & 2) ? xatoul_range(size, 2, INT_MAX) : 16384;
    29         buf = xmalloc(len);
    30         if (0 > (len = klogctl(3 + (flags & 1), buf, len)))
    31             bb_perror_msg_and_die("klogctl");
    32 
    33         // Skip <#> at the start of lines, and make sure we end with a newline.
    34 
    35         if (ENABLE_FEATURE_DMESG_PRETTY) {
    36             int last = '\n';
    37             int in;
    38 
    39             for (in = 0; in<len;) {
    40                 if (last == '\n' && buf[in] == '<') in += 3;
    41                 else putchar(last = buf[in++]);
    42             }
    43             if (last != '\n') putchar('\n');
    44         } else {
    45             write(1,buf,len);
    46             if (len && buf[len-1]!='\n') putchar('\n');
    47         }
    48 
    49         if (ENABLE_FEATURE_CLEAN_UP) free(buf);
     31        return EXIT_SUCCESS;
    5032    }
    5133
    52     return 0;
     34    if (!(opts & OPT_s))
     35        len = klogctl(10, NULL, 0); /* read ring buffer size */
     36    if (len < 16*1024)
     37        len = 16*1024;
     38    if (len > 16*1024*1024)
     39        len = 16*1024*1024;
     40
     41    buf = xmalloc(len);
     42    len = klogctl(3 + (opts & OPT_c), buf, len); /* read ring buffer */
     43    if (len < 0)
     44        bb_perror_msg_and_die("klogctl");
     45    if (len == 0)
     46        return EXIT_SUCCESS;
     47
     48
     49    if (ENABLE_FEATURE_DMESG_PRETTY) {
     50        int last = '\n';
     51        int in = 0;
     52
     53        /* Skip <#> at the start of lines */
     54        while (1) {
     55            if (last == '\n' && buf[in] == '<') {
     56                in += 3;
     57                if (in >= len)
     58                    break;
     59            }
     60            last = buf[in];
     61            putchar(last);
     62            in++;
     63            if (in >= len)
     64                break;
     65        }
     66        /* Make sure we end with a newline */
     67        if (last != '\n')
     68            bb_putchar('\n');
     69    } else {
     70        full_write(STDOUT_FILENO, buf, len);
     71        if (buf[len-1] != '\n')
     72            bb_putchar('\n');
     73    }
     74
     75    if (ENABLE_FEATURE_CLEAN_UP) free(buf);
     76
     77    return EXIT_SUCCESS;
    5378}
Note: See TracChangeset for help on using the changeset viewer.