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>
tunelp_SOURCES = tunelp.c lp.h
fstrim_SOURCES = fstrim.c $(top_srcdir)/lib/strutils.c
rtcwake_SOURCES = rtcwake.c $(top_srcdir)/lib/strutils.c
+dmesg_SOURCES = dmesg.c $(top_srcdir)/lib/strutils.c
if BUILD_FALLOCATE
usrbin_exec_PROGRAMS += fallocate
#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;
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;
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) {
if (n < 0) {
perror("klogctl");
- exit(1);
+ exit(EXIT_FAILURE);
}
lastc = '\n';