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