]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/dmesg.c
1 /* dmesg.c -- Print out the contents of the kernel ring buffer
2 * Created: Sat Oct 9 16:19:47 1993
3 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu
4 * Copyright 1993 Theodore Ts'o (tytso@athena.mit.edu)
5 * This program comes with ABSOLUTELY NO WARRANTY.
6 * Modifications by Rick Sladkey (jrs@world.std.com)
7 * Larger buffersize 3 June 1998 by Nicolai Langfeldt, based on a patch
8 * by Peeter Joot. This was also suggested by John Hudson.
9 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
10 * - added Native Language Support
14 #include <linux/unistd.h>
20 #if __GNU_LIBRARY__ < 5
23 # define __NR_klogctl __NR_syslog
24 static inline _syscall3(int, klogctl
, int, type
, char *, b
, int, len
);
26 #define klogctl syslog
30 # include <sys/klog.h>
33 static char *progname
;
37 fprintf( stderr
, _("Usage: %s [-c] [-n level] [-s bufsize]\n"), progname
);
41 main( int argc
, char *argv
[] ) {
51 setlocale(LC_ALL
, "");
52 bindtextdomain(PACKAGE
, LOCALEDIR
);
56 while ((c
= getopt( argc
, argv
, "cn:s:" )) != EOF
) {
66 bufsize
= atoi(optarg
);
83 n
= klogctl( cmd
, NULL
, level
);
91 if (bufsize
< 4096) bufsize
= 4096;
92 buf
= (char*)malloc(bufsize
);
93 n
= klogctl( cmd
, buf
, bufsize
);
100 for (i
= 0; i
< n
; i
++) {
101 if ((i
== 0 || buf
[i
- 1] == '\n') && buf
[i
] == '<') {
103 while (buf
[i
] >= '0' && buf
[i
] <= '9')