summaryrefslogtreecommitdiffstats
path: root/sys-utils/dmesg.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2011-02-03 21:41:56 +0100
committerKarel Zak2011-02-08 15:40:48 +0100
commit15673c1598e8eb138b569f9e86421d1b60f76c23 (patch)
treea8bbb687d1390abb4ff2dec7a155bb7e84d0e17b /sys-utils/dmesg.c
parentlscpu: cleanup usage() (diff)
downloadkernel-qcow2-util-linux-15673c1598e8eb138b569f9e86421d1b60f76c23.tar.gz
kernel-qcow2-util-linux-15673c1598e8eb138b569f9e86421d1b60f76c23.tar.xz
kernel-qcow2-util-linux-15673c1598e8eb138b569f9e86421d1b60f76c23.zip
dmesg: use strtol_or_err instead of atoi
We shouldn't be accepting things like 'dmesg -n 2crapinput' This patch also changes the exit's value to use EXIT_* constants. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'sys-utils/dmesg.c')
-rw-r--r--sys-utils/dmesg.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index f1a7dcb7c..49fd707ab 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -33,9 +33,10 @@
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
-# include <sys/klog.h>
+#include <sys/klog.h>
#include "nls.h"
+#include "strutils.h"
static char *progname;
@@ -70,20 +71,20 @@ main(int argc, char *argv[]) {
break;
case 'n':
cmd = 8; /* Set level of messages */
- level = atoi(optarg);
+ level = strtol_or_err(optarg, _("failed to parse level"));
break;
case 'r':
raw = 1;
break;
case 's':
- bufsize = atoi(optarg);
+ bufsize = strtol_or_err(optarg, _("failed to parse buffer size"));
if (bufsize < 4096)
bufsize = 4096;
break;
case '?':
default:
usage();
- exit(1);
+ exit(EXIT_FAILURE);
}
}
argc -= optind;
@@ -91,16 +92,16 @@ main(int argc, char *argv[]) {
if (argc > 1) {
usage();
- exit(1);
+ exit(EXIT_FAILURE);
}
if (cmd == 8) {
n = klogctl(cmd, NULL, level);
if (n < 0) {
perror("klogctl");
- exit(1);
+ exit(EXIT_FAILURE);
}
- exit(0);
+ exit(EXIT_SUCCESS);
}
if (!bufsize) {
@@ -130,7 +131,7 @@ main(int argc, char *argv[]) {
if (n < 0) {
perror("klogctl");
- exit(1);
+ exit(EXIT_FAILURE);
}
lastc = '\n';