blob: de9c3700f4bcf8758c3a4d76d9d728d2e11360c0 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
2/*
Rob Landley7c7b0d72006-06-13 18:31:04 +00003 *
4 * dmesg - display/control kernel ring buffer.
Eric Andersene77ae3a1999-10-19 20:03:34 +00005 *
Rob Landley7c7b0d72006-06-13 18:31:04 +00006 * Copyring 2006 Rob Landley <rob@landley.net>
Eric Andersen2afcbe42003-03-07 17:33:40 +00007 *
Rob Landley7c7b0d72006-06-13 18:31:04 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersencc8ed391999-10-05 16:24:54 +00009 */
10
Rob Landley7c7b0d72006-06-13 18:31:04 +000011#include "busybox.h"
12#include <unistd.h>
Eric Andersen85e5e722003-07-22 08:56:55 +000013#include <sys/klog.h>
Eric Andersene76c3b02001-04-05 03:14:39 +000014
Rob Landley7c7b0d72006-06-13 18:31:04 +000015int dmesg_main(int argc, char *argv[])
Eric Andersencc8ed391999-10-05 16:24:54 +000016{
Rob Landley7c7b0d72006-06-13 18:31:04 +000017 char *size, *level;
Rob Landleyaa516a62006-07-06 16:41:56 +000018 int flags = bb_getopt_ulflags(argc, argv, "cs:n:", &size, &level);
Erik Andersen1266a131999-12-29 22:19:46 +000019
Rob Landley7c7b0d72006-06-13 18:31:04 +000020 if (flags & 4) {
Rob Landleyaa516a62006-07-06 16:41:56 +000021 if(klogctl(8, NULL, bb_xgetlarg(level, 10, 0, 10)))
Rob Landley7c7b0d72006-06-13 18:31:04 +000022 bb_perror_msg_and_die("klogctl");
23 } else {
24 int len;
25 char *buf;
Eric Andersencc8ed391999-10-05 16:24:54 +000026
Rob Landleyaa516a62006-07-06 16:41:56 +000027 len = (flags & 2) ? bb_xgetlarg(size, 10, 2, INT_MAX) : 16384;
Rob Landley7c7b0d72006-06-13 18:31:04 +000028 buf = xmalloc(len);
29 if (0 > (len = klogctl(3 + (flags & 1), buf, len)))
30 bb_perror_msg_and_die("klogctl");
31 write(1,buf,len);
32 if (len && buf[len-1]!='\n') putchar('\n');
Erik Andersene49d5ec2000-02-08 19:58:47 +000033 }
Eric Andersen3cf52d11999-10-12 22:26:06 +000034
Rob Landley7c7b0d72006-06-13 18:31:04 +000035 return 0;
Eric Andersencc8ed391999-10-05 16:24:54 +000036}