summaryrefslogtreecommitdiffstats
path: root/disk-utils/fsck.c
diff options
context:
space:
mode:
authorKarel Zak2015-04-28 13:43:14 +0200
committerKarel Zak2015-04-28 13:43:14 +0200
commit658c089190cda060bb7c7e24243cffb0b2776c15 (patch)
tree11c4c79c8232795911ad0c797b19872821ff74ae /disk-utils/fsck.c
parentfsck: implement fsck -r {fd} (diff)
downloadkernel-qcow2-util-linux-658c089190cda060bb7c7e24243cffb0b2776c15.tar.gz
kernel-qcow2-util-linux-658c089190cda060bb7c7e24243cffb0b2776c15.tar.xz
kernel-qcow2-util-linux-658c089190cda060bb7c7e24243cffb0b2776c15.zip
fsck: print errors on invalid -r argument
The patch also add support for -r 0. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/fsck.c')
-rw-r--r--disk-utils/fsck.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c
index 6ef8ad198..bd2bf36ca 100644
--- a/disk-utils/fsck.c
+++ b/disk-utils/fsck.c
@@ -56,6 +56,9 @@
#include "fileutils.h"
#include "monotonic.h"
+#define STRTOXX_EXIT_CODE FSCK_EX_ERROR
+#include "strutils.h"
+
#define XALLOC_EXIT_CODE FSCK_EX_ERROR
#include "xalloc.h"
@@ -1413,7 +1416,7 @@ static void parse_argv(int argc, char *argv[])
int opt = 0;
int opts_for_fsck = 0;
struct sigaction sa;
- int report_stats_fd = 0;
+ int report_stats_fd = -1;
/*
* Set up signal action
@@ -1520,19 +1523,12 @@ static void parse_argv(int argc, char *argv[])
case 'r':
report_stats = 1;
if (arg[j+1]) { /* -r<fd> */
- report_stats_fd = string_to_int(arg+j+1);
- if (report_stats_fd < 0)
- report_stats_fd = 0;
- else
- goto next_arg;
+ report_stats_fd = strtou32_or_err(arg+j+1, _("invalid argument -r"));
+ goto next_arg;
} else if (i+1 < argc && *argv[i+1] != '-') { /* -r <fd> */
- report_stats_fd = string_to_int(argv[i+1]);
- if (report_stats_fd < 0)
- report_stats_fd = 0;
- else {
- ++i;
- goto next_arg;
- }
+ report_stats_fd = strtou32_or_err(argv[i+1], _("invalid argument -r"));
+ ++i;
+ goto next_arg;
}
break;
case 's':
@@ -1574,7 +1570,7 @@ static void parse_argv(int argc, char *argv[])
}
/* Validate the report stats file descriptor to avoid disasters */
- if (report_stats_fd) {
+ if (report_stats_fd >= 0) {
report_stats_file = fdopen(report_stats_fd, "w");
if (!report_stats_file)
err(FSCK_EX_ERROR,