- shrink dmesg a bit.
http://busybox.net/lists/busybox/2006-March/019477.html
This commit is contained in:
parent
ca087713f2
commit
b256bd334f
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <getopt.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/klog.h>
|
#include <sys/klog.h>
|
||||||
|
|
||||||
@ -28,71 +27,53 @@
|
|||||||
|
|
||||||
int dmesg_main(int argc, char **argv)
|
int dmesg_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *buf
|
char *buf, *tmp;
|
||||||
#ifdef CONFIG_FEATURE_CLEAN_UP
|
|
||||||
= NULL
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
int bufsize = 8196;
|
int bufsize = 8196;
|
||||||
int i, n;
|
int i, n = 0;
|
||||||
int level = 0;
|
int c = 3;
|
||||||
int lastc;
|
|
||||||
int cmd = 3;
|
|
||||||
|
|
||||||
while ((i = getopt(argc, argv, "cn:s:")) > 0) {
|
i = bb_getopt_ulflags(argc, argv, "cn:s:", &buf, &tmp);
|
||||||
switch (i) {
|
if (i & 1)
|
||||||
case 'c':
|
c = 4;
|
||||||
cmd = 4;
|
if (i & 2) {
|
||||||
break;
|
c = 8;
|
||||||
case 'n':
|
n = bb_xgetlarg(buf, 10, 0, 10);
|
||||||
cmd = 8;
|
}
|
||||||
level = bb_xgetlarg(optarg, 10, 0, 10);
|
if (i & 4)
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
/* I think a 512k max kernel ring buffer is big enough for
|
/* I think a 512k max kernel ring buffer is big enough for
|
||||||
* anybody, as the default is 16k... Could be wrong though.
|
* anybody, as the default is 16k... Could be wrong though.
|
||||||
* If so I'm sure I'll hear about it by the enraged masses*/
|
* If so I'm sure I'll hear about it by the enraged masses*/
|
||||||
bufsize = bb_xgetlarg(optarg, 10, 4096, 512*1024);
|
bufsize = bb_xgetlarg(tmp, 10, 4096, 512*1024);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind < argc) {
|
if (c == 8) {
|
||||||
bb_show_usage();
|
if (klogctl(c, NULL, n) < 0)
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd == 8) {
|
|
||||||
if (klogctl(cmd, NULL, level) < 0)
|
|
||||||
goto die_the_death;
|
goto die_the_death;
|
||||||
goto all_done;
|
goto all_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = xmalloc(bufsize);
|
buf = xmalloc(bufsize);
|
||||||
if ((n = klogctl(cmd, buf, bufsize)) < 0)
|
if ((n = klogctl(c, buf, bufsize)) < 0)
|
||||||
goto die_the_death;
|
goto die_the_death;
|
||||||
|
|
||||||
lastc = '\n';
|
c = '\n';
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (lastc == '\n' && buf[i] == '<') {
|
if (c == '\n' && buf[i] == '<') {
|
||||||
i++;
|
i++;
|
||||||
while (buf[i] >= '0' && buf[i] <= '9')
|
while (buf[i] >= '0' && buf[i] <= '9')
|
||||||
i++;
|
i++;
|
||||||
if (buf[i] == '>')
|
if (buf[i] == '>')
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
lastc = buf[i];
|
c = buf[i];
|
||||||
putchar(lastc);
|
putchar(c);
|
||||||
}
|
}
|
||||||
if (lastc != '\n')
|
if (c != '\n')
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
all_done:
|
all_done:
|
||||||
#ifdef CONFIG_FEATURE_CLEAN_UP
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||||
if (buf) {
|
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
die_the_death:
|
die_the_death:
|
||||||
bb_perror_nomsg_and_die();
|
bb_perror_nomsg_and_die();
|
||||||
|
Loading…
Reference in New Issue
Block a user