1 /* vi: set sw=4 ts=4: */
2 /* dmesg.c -- Print out the contents of the kernel ring buffer
3 * Created: Sat Oct 9 16:19:47 1993
4 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu
5 * Copyright 1993 Theodore Ts'o (tytso@athena.mit.edu)
6 * This program comes with ABSOLUTELY NO WARRANTY.
7 * Modifications by Rick Sladkey (jrs@world.std.com)
8 * Larger buffersize 3 June 1998 by Nicolai Langfeldt, based on a patch
9 * by Peeter Joot. This was also suggested by John Hudson.
10 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
11 * - added Native Language Support
13 * from util-linux -- adapted for busybox by
14 * Erik Andersen <andersee@debian.org>. I ripped out Native Language
15 * Support, replaced getopt, added some gotos for redundant stuff.
19 #include <linux/unistd.h>
24 #if __GNU_LIBRARY__ < 5
27 # define __NR_klogctl __NR_syslog
28 static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
30 #define klogctl syslog
34 # include <sys/klog.h>
37 static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
39 int dmesg_main(int argc, char **argv)
53 /* Parse any options */
54 while (argc && **argv == '-') {
55 stopDoingThat = FALSE;
56 while (stopDoingThat == FALSE && *++(*argv)) {
65 level = atoi(*(++argv));
73 bufsize = atoi(*(++argv));
89 n = klogctl(cmd, NULL, level);
98 buf = (char *) xmalloc(bufsize);
99 n = klogctl(cmd, buf, bufsize);
105 for (i = 0; i < n; i++) {
106 if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
108 while (buf[i] >= '0' && buf[i] <= '9')