summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/dmesg.c63
1 files changed, 22 insertions, 41 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index 2ca8827..2166edb 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -20,7 +20,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <getopt.h>
#include <errno.h>
#include <sys/klog.h>
@@ -28,71 +27,53 @@
int dmesg_main(int argc, char **argv)
{
- char *buf
-#ifdef CONFIG_FEATURE_CLEAN_UP
- = NULL
-#endif
- ;
+ char *buf, *tmp;
int bufsize = 8196;
- int i, n;
- int level = 0;
- int lastc;
- int cmd = 3;
+ int i, n = 0;
+ int c = 3;
- while ((i = getopt(argc, argv, "cn:s:")) > 0) {
- switch (i) {
- case 'c':
- cmd = 4;
- break;
- case 'n':
- cmd = 8;
- level = bb_xgetlarg(optarg, 10, 0, 10);
- break;
- case 's':
+ i = bb_getopt_ulflags(argc, argv, "cn:s:", &buf, &tmp);
+ if (i & 1)
+ c = 4;
+ if (i & 2) {
+ c = 8;
+ n = bb_xgetlarg(buf, 10, 0, 10);
+ }
+ if (i & 4)
/* I think a 512k max kernel ring buffer is big enough for
* anybody, as the default is 16k... Could be wrong though.
* If so I'm sure I'll hear about it by the enraged masses*/
- bufsize = bb_xgetlarg(optarg, 10, 4096, 512*1024);
- break;
- default:
- bb_show_usage();
- }
- }
+ bufsize = bb_xgetlarg(tmp, 10, 4096, 512*1024);
- if (optind < argc) {
- bb_show_usage();
- }
-
- if (cmd == 8) {
- if (klogctl(cmd, NULL, level) < 0)
+ if (c == 8) {
+ if (klogctl(c, NULL, n) < 0)
goto die_the_death;
goto all_done;
}
buf = xmalloc(bufsize);
- if ((n = klogctl(cmd, buf, bufsize)) < 0)
+ if ((n = klogctl(c, buf, bufsize)) < 0)
goto die_the_death;
- lastc = '\n';
+ c = '\n';
for (i = 0; i < n; i++) {
- if (lastc == '\n' && buf[i] == '<') {
+ if (c == '\n' && buf[i] == '<') {
i++;
while (buf[i] >= '0' && buf[i] <= '9')
i++;
if (buf[i] == '>')
i++;
}
- lastc = buf[i];
- putchar(lastc);
+ c = buf[i];
+ putchar(c);
}
- if (lastc != '\n')
+ if (c != '\n')
putchar('\n');
all_done:
-#ifdef CONFIG_FEATURE_CLEAN_UP
- if (buf) {
+ if (ENABLE_FEATURE_CLEAN_UP) {
free(buf);
}
-#endif
+
return EXIT_SUCCESS;
die_the_death:
bb_perror_nomsg_and_die();