summaryrefslogtreecommitdiff
path: root/e2fsprogs/fsck.c
diff options
context:
space:
mode:
Diffstat (limited to 'e2fsprogs/fsck.c')
-rw-r--r--e2fsprogs/fsck.c93
1 files changed, 42 insertions, 51 deletions
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index 3c6cafb..c4d0b03 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -103,9 +103,7 @@ static const char really_wanted[] ALIGN1 =
#define BASE_MD "/dev/md"
-static char **devices;
static char **args;
-static int num_devices;
static int num_args;
static int verbose;
@@ -116,13 +114,10 @@ static char **fs_type_list;
static uint8_t *fs_type_flag;
static smallint fs_type_negated;
-static volatile smallint cancel_requested;
-static smallint doall;
static smallint noexecute;
static smallint serialize;
static smallint skip_root;
/* static smallint like_mount; */
-static smallint notitle;
static smallint parallel_root;
static smallint force_all_parallel;
@@ -353,13 +348,13 @@ static int progress_active(void)
/*
* Send a signal to all outstanding fsck child processes
*/
-static void kill_all_if_cancel_requested(void)
+static void kill_all_if_got_signal(void)
{
static smallint kill_sent;
struct fsck_instance *inst;
- if (!cancel_requested || kill_sent)
+ if (!bb_got_signal || kill_sent)
return;
for (inst = instance_list; inst; inst = inst->next) {
@@ -388,7 +383,7 @@ static int wait_one(int flags)
while (1) {
pid = waitpid(-1, &status, flags);
- kill_all_if_cancel_requested();
+ kill_all_if_got_signal();
if (pid == 0) /* flags == WNOHANG and no children exited */
return -1;
if (pid < 0) {
@@ -788,7 +783,7 @@ static int check_all(void)
pass_done = 1;
for (fs = filesys_info; fs; fs = fs->next) {
- if (cancel_requested)
+ if (bb_got_signal)
break;
if (fs->flags & FLAG_DONE)
continue;
@@ -828,7 +823,7 @@ static int check_all(void)
break;
}
}
- if (cancel_requested)
+ if (bb_got_signal)
break;
if (verbose > 1)
printf("--waiting-- (pass %d)\n", passno);
@@ -841,7 +836,7 @@ static int check_all(void)
} else
not_done_yet = 1;
}
- kill_all_if_cancel_requested();
+ kill_all_if_got_signal();
status |= wait_many(FLAG_WAIT_ATLEAST_ONE);
return status;
}
@@ -904,22 +899,39 @@ static void compile_fs_type(char *fs_type)
}
}
-static void parse_args(char **argv)
+int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int fsck_main(int argc UNUSED_PARAM, char **argv)
{
- int i, j;
- char *arg, *tmp;
- char *options;
- int optpos;
- int opts_for_fsck = 0;
+ int i, status;
+ /*int interactive;*/
+ struct fs_info *fs;
+ const char *fstab;
+ char *tmp;
+ char **devices;
+ int num_devices;
+ smallint opts_for_fsck;
+ smallint doall;
+ smallint notitle;
- /* in bss, so already zeroed
+ /* we want wait() to be interruptible */
+ signal_no_SA_RESTART_empty_mask(SIGINT, record_signo);
+ signal_no_SA_RESTART_empty_mask(SIGTERM, record_signo);
+
+ setbuf(stdout, NULL);
+
+ opts_for_fsck = doall = notitle = 0;
+ devices = NULL;
num_devices = 0;
+ /* in bss, so already zeroed
+ args = NULL;
num_args = 0;
instance_list = NULL;
*/
-
- for (i = 1; argv[i]; i++) {
- arg = argv[i];
+ while (*++argv) {
+ int j;
+ int optpos;
+ char *options;
+ char *arg = *argv;
/* "/dev/blk" or "/path" or "UUID=xxx" or "LABEL=xxx" */
if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
@@ -927,13 +939,13 @@ static void parse_args(char **argv)
// "/path", "UUID=xxx" or "LABEL=xxx" into block device name
// ("UUID=xxx"/"LABEL=xxx" can probably shifted to fsck.auto duties)
devices = xrealloc_vector(devices, 2, num_devices);
- devices[num_devices++] = xstrdup(arg);
+ devices[num_devices++] = arg;
continue;
}
if (arg[0] != '-' || opts_for_fsck) {
args = xrealloc_vector(args, 2, num_args);
- args[num_args++] = xstrdup(arg);
+ args[num_args++] = arg;
continue;
}
@@ -957,8 +969,9 @@ static void parse_args(char **argv)
goto next_arg;
}
/* -C n */
- if (!argv[++i]) bb_show_usage();
- progress_fd = xatoi_u(argv[i]);
+ if (!*++argv)
+ bb_show_usage();
+ progress_fd = xatoi_u(*argv);
goto next_arg;
#endif
case 'V':
@@ -987,8 +1000,8 @@ static void parse_args(char **argv)
bb_show_usage();
if (arg[++j])
tmp = &arg[j];
- else if (argv[++i])
- tmp = argv[i];
+ else if (*++argv)
+ tmp = *argv;
else
bb_show_usage();
fstype = xstrdup(tmp);
@@ -1018,28 +1031,6 @@ static void parse_args(char **argv)
tmp = getenv("FSCK_MAX_INST");
if (tmp)
max_running = xatoi(tmp);
-}
-
-static void signal_cancel(int sig UNUSED_PARAM)
-{
- cancel_requested = 1;
-}
-
-int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int fsck_main(int argc UNUSED_PARAM, char **argv)
-{
- int i, status;
- /*int interactive;*/
- const char *fstab;
- struct fs_info *fs;
-
- /* we want wait() to be interruptible */
- signal_no_SA_RESTART_empty_mask(SIGINT, signal_cancel);
- signal_no_SA_RESTART_empty_mask(SIGTERM, signal_cancel);
-
- setbuf(stdout, NULL);
-
- parse_args(argv);
if (!notitle)
puts("fsck (busybox "BB_VER", "BB_BT")");
@@ -1060,8 +1051,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
status = 0;
for (i = 0; i < num_devices; i++) {
- if (cancel_requested) {
- kill_all_if_cancel_requested();
+ if (bb_got_signal) {
+ kill_all_if_got_signal();
break;
}