fsck: remove a few statics

function                                             old     new   delta
kill_all_if_got_signal                                 -      60     +60
notitle                                                1       -      -1
doall                                                  1       -      -1
cancel_requested                                       1       -      -1
num_devices                                            4       -      -4
devices                                                4       -      -4
signal_cancel                                          8       -      -8
fsck_main                                           1893    1870     -23
kill_all_if_cancel_requested                          60       -     -60
------------------------------------------------------------------------------
(add/remove: 1/7 grow/shrink: 0/1 up/down: 60/-102)           Total: -42 bytes
   text    data     bss     dec     hex filename
 824205     458    6956  831619   cb083 busybox_old
 824174     458    6948  831580   cb05c busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-09-13 05:52:03 +02:00
parent c541a8955d
commit 6683745bf7

View File

@ -103,9 +103,7 @@ static const char really_wanted[] ALIGN1 =
#define BASE_MD "/dev/md" #define BASE_MD "/dev/md"
static char **devices;
static char **args; static char **args;
static int num_devices;
static int num_args; static int num_args;
static int verbose; static int verbose;
@ -116,13 +114,10 @@ static char **fs_type_list;
static uint8_t *fs_type_flag; static uint8_t *fs_type_flag;
static smallint fs_type_negated; static smallint fs_type_negated;
static volatile smallint cancel_requested;
static smallint doall;
static smallint noexecute; static smallint noexecute;
static smallint serialize; static smallint serialize;
static smallint skip_root; static smallint skip_root;
/* static smallint like_mount; */ /* static smallint like_mount; */
static smallint notitle;
static smallint parallel_root; static smallint parallel_root;
static smallint force_all_parallel; static smallint force_all_parallel;
@ -353,13 +348,13 @@ static int progress_active(void)
/* /*
* Send a signal to all outstanding fsck child processes * 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; static smallint kill_sent;
struct fsck_instance *inst; struct fsck_instance *inst;
if (!cancel_requested || kill_sent) if (!bb_got_signal || kill_sent)
return; return;
for (inst = instance_list; inst; inst = inst->next) { for (inst = instance_list; inst; inst = inst->next) {
@ -388,7 +383,7 @@ static int wait_one(int flags)
while (1) { while (1) {
pid = waitpid(-1, &status, flags); pid = waitpid(-1, &status, flags);
kill_all_if_cancel_requested(); kill_all_if_got_signal();
if (pid == 0) /* flags == WNOHANG and no children exited */ if (pid == 0) /* flags == WNOHANG and no children exited */
return -1; return -1;
if (pid < 0) { if (pid < 0) {
@ -788,7 +783,7 @@ static int check_all(void)
pass_done = 1; pass_done = 1;
for (fs = filesys_info; fs; fs = fs->next) { for (fs = filesys_info; fs; fs = fs->next) {
if (cancel_requested) if (bb_got_signal)
break; break;
if (fs->flags & FLAG_DONE) if (fs->flags & FLAG_DONE)
continue; continue;
@ -828,7 +823,7 @@ static int check_all(void)
break; break;
} }
} }
if (cancel_requested) if (bb_got_signal)
break; break;
if (verbose > 1) if (verbose > 1)
printf("--waiting-- (pass %d)\n", passno); printf("--waiting-- (pass %d)\n", passno);
@ -841,7 +836,7 @@ static int check_all(void)
} else } else
not_done_yet = 1; not_done_yet = 1;
} }
kill_all_if_cancel_requested(); kill_all_if_got_signal();
status |= wait_many(FLAG_WAIT_ATLEAST_ONE); status |= wait_many(FLAG_WAIT_ATLEAST_ONE);
return status; 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; int i, status;
char *arg, *tmp; /*int interactive;*/
char *options; struct fs_info *fs;
int optpos; const char *fstab;
int opts_for_fsck = 0; 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; num_devices = 0;
/* in bss, so already zeroed
args = NULL;
num_args = 0; num_args = 0;
instance_list = NULL; instance_list = NULL;
*/ */
while (*++argv) {
for (i = 1; argv[i]; i++) { int j;
arg = argv[i]; int optpos;
char *options;
char *arg = *argv;
/* "/dev/blk" or "/path" or "UUID=xxx" or "LABEL=xxx" */ /* "/dev/blk" or "/path" or "UUID=xxx" or "LABEL=xxx" */
if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) { 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 // "/path", "UUID=xxx" or "LABEL=xxx" into block device name
// ("UUID=xxx"/"LABEL=xxx" can probably shifted to fsck.auto duties) // ("UUID=xxx"/"LABEL=xxx" can probably shifted to fsck.auto duties)
devices = xrealloc_vector(devices, 2, num_devices); devices = xrealloc_vector(devices, 2, num_devices);
devices[num_devices++] = xstrdup(arg); devices[num_devices++] = arg;
continue; continue;
} }
if (arg[0] != '-' || opts_for_fsck) { if (arg[0] != '-' || opts_for_fsck) {
args = xrealloc_vector(args, 2, num_args); args = xrealloc_vector(args, 2, num_args);
args[num_args++] = xstrdup(arg); args[num_args++] = arg;
continue; continue;
} }
@ -957,8 +969,9 @@ static void parse_args(char **argv)
goto next_arg; goto next_arg;
} }
/* -C n */ /* -C n */
if (!argv[++i]) bb_show_usage(); if (!*++argv)
progress_fd = xatoi_u(argv[i]); bb_show_usage();
progress_fd = xatoi_u(*argv);
goto next_arg; goto next_arg;
#endif #endif
case 'V': case 'V':
@ -987,8 +1000,8 @@ static void parse_args(char **argv)
bb_show_usage(); bb_show_usage();
if (arg[++j]) if (arg[++j])
tmp = &arg[j]; tmp = &arg[j];
else if (argv[++i]) else if (*++argv)
tmp = argv[i]; tmp = *argv;
else else
bb_show_usage(); bb_show_usage();
fstype = xstrdup(tmp); fstype = xstrdup(tmp);
@ -1018,28 +1031,6 @@ static void parse_args(char **argv)
tmp = getenv("FSCK_MAX_INST"); tmp = getenv("FSCK_MAX_INST");
if (tmp) if (tmp)
max_running = xatoi(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) if (!notitle)
puts("fsck (busybox "BB_VER", "BB_BT")"); puts("fsck (busybox "BB_VER", "BB_BT")");
@ -1060,8 +1051,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
status = 0; status = 0;
for (i = 0; i < num_devices; i++) { for (i = 0; i < num_devices; i++) {
if (cancel_requested) { if (bb_got_signal) {
kill_all_if_cancel_requested(); kill_all_if_got_signal();
break; break;
} }