"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 3 | * |
| 4 | * dmesg - display/control kernel ring buffer. |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 5 | * |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 6 | * Copyring 2006 Rob Landley <rob@landley.net> |
Eric Andersen | 2afcbe4 | 2003-03-07 17:33:40 +0000 | [diff] [blame] | 7 | * |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 11 | #include "busybox.h" |
| 12 | #include <unistd.h> |
Eric Andersen | 85e5e72 | 2003-07-22 08:56:55 +0000 | [diff] [blame] | 13 | #include <sys/klog.h> |
Eric Andersen | e76c3b0 | 2001-04-05 03:14:39 +0000 | [diff] [blame] | 14 | |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 15 | int dmesg_main(int argc, char *argv[]) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 16 | { |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 17 | char *size, *level; |
Rob Landley | aa516a6 | 2006-07-06 16:41:56 +0000 | [diff] [blame] | 18 | int flags = bb_getopt_ulflags(argc, argv, "cs:n:", &size, &level); |
Erik Andersen | 1266a13 | 1999-12-29 22:19:46 +0000 | [diff] [blame] | 19 | |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 20 | if (flags & 4) { |
Rob Landley | aa516a6 | 2006-07-06 16:41:56 +0000 | [diff] [blame] | 21 | if(klogctl(8, NULL, bb_xgetlarg(level, 10, 0, 10))) |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 22 | bb_perror_msg_and_die("klogctl"); |
| 23 | } else { |
| 24 | int len; |
| 25 | char *buf; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 26 | |
Rob Landley | aa516a6 | 2006-07-06 16:41:56 +0000 | [diff] [blame] | 27 | len = (flags & 2) ? bb_xgetlarg(size, 10, 2, INT_MAX) : 16384; |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 28 | 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 Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 33 | } |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 34 | |
Rob Landley | 7c7b0d7 | 2006-06-13 18:31:04 +0000 | [diff] [blame] | 35 | return 0; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 36 | } |