summaryrefslogtreecommitdiffstats
path: root/sys-utils/dmesg.c
diff options
context:
space:
mode:
authorSami Kerola2012-06-16 11:31:47 +0200
committerSami Kerola2012-06-17 17:59:59 +0200
commit9492013429d0d9fd6e3bbe7cf5fe6f3ee37e4abe (patch)
treee80ef3715ec3fec21a9283c4075d57eb6c039417 /sys-utils/dmesg.c
parentwipefs: use exclusive_option() (diff)
downloadkernel-qcow2-util-linux-9492013429d0d9fd6e3bbe7cf5fe6f3ee37e4abe.tar.gz
kernel-qcow2-util-linux-9492013429d0d9fd6e3bbe7cf5fe6f3ee37e4abe.tar.xz
kernel-qcow2-util-linux-9492013429d0d9fd6e3bbe7cf5fe6f3ee37e4abe.zip
dmesg: use exclusive_option()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/dmesg.c')
-rw-r--r--sys-utils/dmesg.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 854990361..9fc7982a1 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -30,6 +30,7 @@
#include "all-io.h"
#include "bitops.h"
#include "closestream.h"
+#include "optutils.h"
/* Close the log. Currently a NOP. */
#define SYSLOG_ACTION_CLOSE 0
@@ -54,6 +55,8 @@
/* Return size of the log buffer */
#define SYSLOG_ACTION_SIZE_BUFFER 10
+#define EXCL_ERROR "--{clear,read-clear,console-level,console-on,console-off}"
+
/*
* Priority and facility names
*/
@@ -664,6 +667,16 @@ int main(int argc, char *argv[])
int cmd = -1;
static struct dmesg_control ctl;
+ enum {
+ EXCL_NONE,
+ EXCL_CLEAR,
+ EXCL_READ_CLEAR,
+ EXCL_CONSOLE_LEVEL,
+ EXCL_CONSOLE_ON,
+ EXCL_CONSOLE_OFF
+ };
+ int excl_any = EXCL_NONE;
+
static const struct option longopts[] = {
{ "buffer-size", required_argument, NULL, 's' },
{ "clear", no_argument, NULL, 'C' },
@@ -693,26 +706,24 @@ int main(int argc, char *argv[])
while ((c = getopt_long(argc, argv, "CcDdEF:f:hkl:n:rs:TtuVx",
longopts, NULL)) != -1) {
-
- if (cmd != -1 && strchr("CcnDE", c))
- errx(EXIT_FAILURE, _("clear, read-clear, console-level, "
- "console-on, and console-off options are mutually "
- "exclusive"));
-
switch (c) {
case 'C':
+ exclusive_option(&excl_any, EXCL_CLEAR, EXCL_ERROR);
cmd = SYSLOG_ACTION_CLEAR;
break;
case 'c':
+ exclusive_option(&excl_any, EXCL_READ_CLEAR, EXCL_ERROR);
cmd = SYSLOG_ACTION_READ_CLEAR;
break;
case 'D':
+ exclusive_option(&excl_any, EXCL_CONSOLE_OFF, EXCL_ERROR);
cmd = SYSLOG_ACTION_CONSOLE_OFF;
break;
case 'd':
ctl.delta = 1;
break;
case 'E':
+ exclusive_option(&excl_any, EXCL_CONSOLE_ON, EXCL_ERROR);
cmd = SYSLOG_ACTION_CONSOLE_ON;
break;
case 'F':
@@ -738,6 +749,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
break;
case 'n':
+ exclusive_option(&excl_any, EXCL_CONSOLE_LEVEL, EXCL_ERROR);
cmd = SYSLOG_ACTION_CONSOLE_LEVEL;
console_level = parse_level(optarg, 0);
break;