From b5b82d92d26934b3d49adb146e8a4bd542ab8dfb Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 20 Nov 2007 01:06:29 -0600 Subject: Implement dmesg. --- toys/Config.in | 12 ++++++++++++ toys/dmesg.c | 40 ++++++++++++++++++++++++++++++++++++++++ toys/toylist.h | 7 +++++++ 3 files changed, 59 insertions(+) create mode 100644 toys/dmesg.c (limited to 'toys') diff --git a/toys/Config.in b/toys/Config.in index 84b3f28f..04640c58 100644 --- a/toys/Config.in +++ b/toys/Config.in @@ -68,6 +68,18 @@ config DF_PEDANTIC -k Sets units back to 1024 bytes (the default without -P) +config DMESG + bool "dmesg" + default y + help + usage: dmesg [-n level] [-s bufsize] | -c + + Print or control the kernel ring buffer. + + -n Set kernel logging level (1-9). + -s Size of buffer to read (in bytes), default 16384. + -c Clear the ring buffer after printing. + config ECHO bool "echo" default y diff --git a/toys/dmesg.c b/toys/dmesg.c new file mode 100644 index 00000000..7a150121 --- /dev/null +++ b/toys/dmesg.c @@ -0,0 +1,40 @@ +/* vi: set sw=4 ts=4: */ +/* + * dmesg.c - display/control kernel ring buffer. + * + * Copyright 2006 Rob Landley + */ + +#include "toys.h" +#include + +#define TT toy.dmesg + +int dmesg_main(void) +{ + // For -n just tell kernel to which messages to keep. + if (toys.optflags & 2) { + if (klogctl(8, NULL, TT.level)) + error_exit("klogctl"); + } else { + int size, i, last = '\n'; + char *data; + + // Figure out how much data we need, and fetch it. + size = TT.size; + if (size<2) size = 16384; + data = xmalloc(size); + size = klogctl(3 + (toys.optflags&1), data, size); + if (size < 0) error_exit("klogctl"); + + // Display data, filtering out level markers. + for (i=0; i2g:Fnqm#N#i#b#" +struct dmesg_data { + long level; + long size; +}; + struct mke2fs_data { // Command line arguments. long blocksize; @@ -67,6 +72,7 @@ struct mkfifo_data { }; extern union toy_union { + struct dmesg_data dmesg; struct df_data df; struct mke2fs_data mke2fs; struct mkfifo_data mkfifo; @@ -104,6 +110,7 @@ USE_CATV(NEWTOY(catv, "vte", TOYFLAG_USR|TOYFLAG_BIN)) USE_COUNT(NEWTOY(count, "", TOYFLAG_USR|TOYFLAG_BIN)) USE_TOYSH(NEWTOY(cd, NULL, TOYFLAG_NOFORK)) USE_DF(NEWTOY(df, "Pkt*a", TOYFLAG_USR|TOYFLAG_SBIN)) +USE_DMESG(NEWTOY(dmesg, "s#n#c", TOYFLAG_BIN)) USE_ECHO(NEWTOY(echo, "+en", TOYFLAG_BIN)) USE_TOYSH(NEWTOY(exit, NULL, TOYFLAG_NOFORK)) USE_FALSE(NEWTOY(false, NULL, TOYFLAG_BIN)) -- cgit v1.2.3