diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-13 05:52:46 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-13 05:52:46 +0200 |
commit | 7649bd024cbfcc12693ddd5c172cba93497aaed3 (patch) | |
tree | cea9d69640ac23956847412e7497f905a0957867 | |
parent | 6683745bf78917562af843ecd17c4f3d04313a77 (diff) | |
download | busybox-w32-7649bd024cbfcc12693ddd5c172cba93497aaed3.tar.gz busybox-w32-7649bd024cbfcc12693ddd5c172cba93497aaed3.tar.bz2 busybox-w32-7649bd024cbfcc12693ddd5c172cba93497aaed3.zip |
fsck: more clever (->smaller) handling of parameters
function old new delta
fsck_device 213 449 +236
new_args - 46 +46
fsck_main 1870 1815 -55
execute 289 - -289
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/1 up/down: 282/-344) Total: -62 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | e2fsprogs/fsck.c | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index c4d0b03ef..21b2fdc0d 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c | |||
@@ -490,60 +490,55 @@ static int wait_many(int flags) | |||
490 | static void execute(const char *type, const char *device, | 490 | static void execute(const char *type, const char *device, |
491 | const char *mntpt /*, int interactive */) | 491 | const char *mntpt /*, int interactive */) |
492 | { | 492 | { |
493 | char *argv[num_args + 4]; /* see count below: */ | ||
494 | int argc; | ||
495 | int i; | 493 | int i; |
496 | struct fsck_instance *inst; | 494 | struct fsck_instance *inst; |
497 | pid_t pid; | 495 | pid_t pid; |
498 | 496 | ||
499 | argv[0] = xasprintf("fsck.%s", type); /* 1 */ | 497 | args[0] = xasprintf("fsck.%s", type); |
500 | for (i = 0; i < num_args; i++) | ||
501 | argv[i+1] = args[i]; /* num_args */ | ||
502 | argc = num_args + 1; | ||
503 | 498 | ||
504 | #if DO_PROGRESS_INDICATOR | 499 | #if DO_PROGRESS_INDICATOR |
505 | if (progress && !progress_active()) { | 500 | if (progress && !progress_active()) { |
506 | if (strcmp(type, "ext2") == 0 | 501 | if (strcmp(type, "ext2") == 0 |
507 | || strcmp(type, "ext3") == 0 | 502 | || strcmp(type, "ext3") == 0 |
508 | ) { | 503 | ) { |
509 | argv[argc++] = xasprintf("-C%d", progress_fd); /* 1 */ | 504 | args[XXX] = xasprintf("-C%d", progress_fd); /* 1 */ |
510 | inst->flags |= FLAG_PROGRESS; | 505 | inst->flags |= FLAG_PROGRESS; |
511 | } | 506 | } |
512 | } | 507 | } |
513 | #endif | 508 | #endif |
514 | 509 | ||
515 | argv[argc++] = (char*)device; /* 1 */ | 510 | args[num_args - 2] = (char*)device; |
516 | argv[argc] = NULL; /* 1 */ | 511 | /* args[num_args - 1] = NULL; - already is */ |
517 | 512 | ||
518 | if (verbose || noexecute) { | 513 | if (verbose || noexecute) { |
519 | printf("[%s (%d) -- %s]", argv[0], num_running, | 514 | printf("[%s (%d) -- %s]", args[0], num_running, |
520 | mntpt ? mntpt : device); | 515 | mntpt ? mntpt : device); |
521 | for (i = 0; i < argc; i++) | 516 | for (i = 0; args[i]; i++) |
522 | printf(" %s", argv[i]); | 517 | printf(" %s", args[i]); |
523 | bb_putchar('\n'); | 518 | bb_putchar('\n'); |
524 | } | 519 | } |
525 | 520 | ||
526 | /* Fork and execute the correct program. */ | 521 | /* Fork and execute the correct program. */ |
527 | pid = -1; | 522 | pid = -1; |
528 | if (!noexecute) { | 523 | if (!noexecute) { |
529 | pid = spawn(argv); | 524 | pid = spawn(args); |
530 | if (pid < 0) | 525 | if (pid < 0) |
531 | bb_simple_perror_msg(argv[0]); | 526 | bb_simple_perror_msg(args[0]); |
532 | } | 527 | } |
533 | 528 | ||
534 | #if DO_PROGRESS_INDICATOR | 529 | #if DO_PROGRESS_INDICATOR |
535 | free(argv[num_args + 1]); | 530 | free(args[XXX]); |
536 | #endif | 531 | #endif |
537 | 532 | ||
538 | /* No child, so don't record an instance */ | 533 | /* No child, so don't record an instance */ |
539 | if (pid <= 0) { | 534 | if (pid <= 0) { |
540 | free(argv[0]); | 535 | free(args[0]); |
541 | return; | 536 | return; |
542 | } | 537 | } |
543 | 538 | ||
544 | inst = xzalloc(sizeof(*inst)); | 539 | inst = xzalloc(sizeof(*inst)); |
545 | inst->pid = pid; | 540 | inst->pid = pid; |
546 | inst->prog = argv[0]; | 541 | inst->prog = args[0]; |
547 | inst->device = xstrdup(device); | 542 | inst->device = xstrdup(device); |
548 | inst->base_device = base_device(device); | 543 | inst->base_device = base_device(device); |
549 | #if DO_PROGRESS_INDICATOR | 544 | #if DO_PROGRESS_INDICATOR |
@@ -899,6 +894,12 @@ static void compile_fs_type(char *fs_type) | |||
899 | } | 894 | } |
900 | } | 895 | } |
901 | 896 | ||
897 | static char **new_args(void) | ||
898 | { | ||
899 | args = xrealloc_vector(args, 2, num_args); | ||
900 | return &args[num_args++]; | ||
901 | } | ||
902 | |||
902 | int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 903 | int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
903 | int fsck_main(int argc UNUSED_PARAM, char **argv) | 904 | int fsck_main(int argc UNUSED_PARAM, char **argv) |
904 | { | 905 | { |
@@ -922,11 +923,9 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) | |||
922 | opts_for_fsck = doall = notitle = 0; | 923 | opts_for_fsck = doall = notitle = 0; |
923 | devices = NULL; | 924 | devices = NULL; |
924 | num_devices = 0; | 925 | num_devices = 0; |
925 | /* in bss, so already zeroed | 926 | new_args(); /* args[0] = NULL, will be replaced by fsck.<type> */ |
926 | args = NULL; | 927 | /* instance_list = NULL; - in bss, so already zeroed */ |
927 | num_args = 0; | 928 | |
928 | instance_list = NULL; | ||
929 | */ | ||
930 | while (*++argv) { | 929 | while (*++argv) { |
931 | int j; | 930 | int j; |
932 | int optpos; | 931 | int optpos; |
@@ -944,8 +943,7 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) | |||
944 | } | 943 | } |
945 | 944 | ||
946 | if (arg[0] != '-' || opts_for_fsck) { | 945 | if (arg[0] != '-' || opts_for_fsck) { |
947 | args = xrealloc_vector(args, 2, num_args); | 946 | *new_args() = arg; |
948 | args[num_args++] = arg; | ||
949 | continue; | 947 | continue; |
950 | } | 948 | } |
951 | 949 | ||
@@ -1022,8 +1020,7 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) | |||
1022 | if (optpos) { | 1020 | if (optpos) { |
1023 | options[0] = '-'; | 1021 | options[0] = '-'; |
1024 | options[optpos + 1] = '\0'; | 1022 | options[optpos + 1] = '\0'; |
1025 | args = xrealloc_vector(args, 2, num_args); | 1023 | *new_args() = options; |
1026 | args[num_args++] = options; | ||
1027 | } | 1024 | } |
1028 | } | 1025 | } |
1029 | if (getenv("FSCK_FORCE_ALL_PARALLEL")) | 1026 | if (getenv("FSCK_FORCE_ALL_PARALLEL")) |
@@ -1031,6 +1028,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) | |||
1031 | tmp = getenv("FSCK_MAX_INST"); | 1028 | tmp = getenv("FSCK_MAX_INST"); |
1032 | if (tmp) | 1029 | if (tmp) |
1033 | max_running = xatoi(tmp); | 1030 | max_running = xatoi(tmp); |
1031 | new_args(); /* args[num_args - 2] will be replaced by <device> */ | ||
1032 | new_args(); /* args[num_args - 1] is the last, NULL element */ | ||
1034 | 1033 | ||
1035 | if (!notitle) | 1034 | if (!notitle) |
1036 | puts("fsck (busybox "BB_VER", "BB_BT")"); | 1035 | puts("fsck (busybox "BB_VER", "BB_BT")"); |