aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 08:59:19 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 08:59:19 +0000
commita55bd05f3cea6c7cbfb45d15009cb70570c2a43b (patch)
treef156fc43098bb02d6108c61534df3da407dd9959
parent397de617f38a58ca4659ee348faf1df574b3ec8d (diff)
downloadbusybox-w32-a55bd05f3cea6c7cbfb45d15009cb70570c2a43b.tar.gz
busybox-w32-a55bd05f3cea6c7cbfb45d15009cb70570c2a43b.tar.bz2
busybox-w32-a55bd05f3cea6c7cbfb45d15009cb70570c2a43b.zip
fsck: shrink (we were passing around some params which were unused)
function old new delta fsck_main 1807 2256 +449 fsck_device 196 189 -7 create_fs_device 131 124 -7 wait_one 325 309 -16 wait_many 52 33 -19 free_instance 38 - -38 packed_usage 23698 23650 -48 execute 2508 2402 -106 check_all 609 - -609 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 1/6 up/down: 449/-850) Total: -401 bytes text data bss dec hex filename 797604 658 7428 805690 c4b3a busybox_old 797195 658 7428 805281 c49a1 busybox_unstripped
-rw-r--r--e2fsprogs/fsck.c237
1 files changed, 100 insertions, 137 deletions
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index 037a563f4..6769a7237 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -39,6 +39,11 @@
39 39
40#include "libbb.h" 40#include "libbb.h"
41 41
42/* "progress indicator" code is somewhat buggy and ext[23] specific.
43 * We should be filesystem agnostic. IOW: there should be a well-defined
44 * API for fsck.something, NOT ad-hoc hacks in generic fsck. */
45#define DO_PROGRESS_INDICATOR 0
46
42#define EXIT_OK 0 47#define EXIT_OK 0
43#define EXIT_NONDESTRUCT 1 48#define EXIT_NONDESTRUCT 1
44#define EXIT_DESTRUCT 2 49#define EXIT_DESTRUCT 2
@@ -57,7 +62,6 @@ struct fs_info {
57 char *mountpt; 62 char *mountpt;
58 char *type; 63 char *type;
59 char *opts; 64 char *opts;
60 int freq;
61 int passno; 65 int passno;
62 int flags; 66 int flags;
63}; 67};
@@ -71,10 +75,10 @@ struct fsck_instance {
71 struct fsck_instance *next; 75 struct fsck_instance *next;
72 int pid; 76 int pid;
73 int flags; 77 int flags;
74 int exit_status; 78#if DO_PROGRESS_INDICATOR
75 time_t start_time; 79 time_t start_time;
80#endif
76 char *prog; 81 char *prog;
77 char *type;
78 char *device; 82 char *device;
79 char *base_device; /* /dev/hda for /dev/hdaN etc */ 83 char *base_device; /* /dev/hda for /dev/hdaN etc */
80}; 84};
@@ -125,10 +129,6 @@ static smallint notitle;
125static smallint parallel_root; 129static smallint parallel_root;
126static smallint force_all_parallel; 130static smallint force_all_parallel;
127 131
128/* "progress indicator" code is somewhat buggy and ext[23] specific.
129 * We should be filesystem agnostic. IOW: there should be a well-defined
130 * API for fsck.something, NOT ad-hoc hacks in generic fsck. */
131#define DO_PROGRESS_INDICATOR 0
132#if DO_PROGRESS_INDICATOR 132#if DO_PROGRESS_INDICATOR
133static smallint progress; 133static smallint progress;
134static int progress_fd; 134static int progress_fd;
@@ -273,7 +273,7 @@ static void free_instance(struct fsck_instance *p)
273 273
274static struct fs_info *create_fs_device(const char *device, const char *mntpnt, 274static struct fs_info *create_fs_device(const char *device, const char *mntpnt,
275 const char *type, const char *opts, 275 const char *type, const char *opts,
276 int freq, int passno) 276 int passno)
277{ 277{
278 struct fs_info *fs; 278 struct fs_info *fs;
279 279
@@ -282,7 +282,6 @@ static struct fs_info *create_fs_device(const char *device, const char *mntpnt,
282 fs->mountpt = xstrdup(mntpnt); 282 fs->mountpt = xstrdup(mntpnt);
283 fs->type = xstrdup(type); 283 fs->type = xstrdup(type);
284 fs->opts = xstrdup(opts ? opts : ""); 284 fs->opts = xstrdup(opts ? opts : "");
285 fs->freq = freq;
286 fs->passno = passno; 285 fs->passno = passno;
287 /*fs->flags = 0; */ 286 /*fs->flags = 0; */
288 /*fs->next = NULL; */ 287 /*fs->next = NULL; */
@@ -344,10 +343,10 @@ static void parse_escape(char *word)
344 343
345static int parse_fstab_line(char *line, struct fs_info **ret_fs) 344static int parse_fstab_line(char *line, struct fs_info **ret_fs)
346{ 345{
347 char *device, *mntpnt, *type, *opts, *freq, *passno, *cp; 346 char *device, *mntpnt, *type, *opts, *passno, *cp;
348 struct fs_info *fs; 347 struct fs_info *fs;
349 348
350 *ret_fs = 0; 349 *ret_fs = NULL;
351 strip_line(line); 350 strip_line(line);
352 *strchrnul(line, '#') = '\0'; /* Ignore everything after comment */ 351 *strchrnul(line, '#') = '\0'; /* Ignore everything after comment */
353 cp = line; 352 cp = line;
@@ -357,7 +356,7 @@ static int parse_fstab_line(char *line, struct fs_info **ret_fs)
357 mntpnt = parse_word(&cp); 356 mntpnt = parse_word(&cp);
358 type = parse_word(&cp); 357 type = parse_word(&cp);
359 opts = parse_word(&cp); 358 opts = parse_word(&cp);
360 freq = parse_word(&cp); 359 /*freq =*/ parse_word(&cp);
361 passno = parse_word(&cp); 360 passno = parse_word(&cp);
362 361
363 if (!mntpnt || !type) 362 if (!mntpnt || !type)
@@ -367,15 +366,13 @@ static int parse_fstab_line(char *line, struct fs_info **ret_fs)
367 parse_escape(mntpnt); 366 parse_escape(mntpnt);
368 parse_escape(type); 367 parse_escape(type);
369 parse_escape(opts); 368 parse_escape(opts);
370 parse_escape(freq);
371 parse_escape(passno); 369 parse_escape(passno);
372 370
373 if (strchr(type, ',')) 371 if (strchr(type, ','))
374 type = NULL; 372 type = NULL;
375 373
376 fs = create_fs_device(device, mntpnt, type ? type : "auto", opts, 374 fs = create_fs_device(device, mntpnt, type ? type : "auto", opts,
377 freq ? atoi(freq) : -1, 375 (passno ? atoi(passno) : -1));
378 passno ? atoi(passno) : -1);
379 *ret_fs = fs; 376 *ret_fs = fs;
380 return 0; 377 return 0;
381} 378}
@@ -477,9 +474,10 @@ static void kill_all_if_cancel_requested(void)
477 474
478/* 475/*
479 * Wait for one child process to exit; when it does, unlink it from 476 * Wait for one child process to exit; when it does, unlink it from
480 * the list of executing child processes, and return it. 477 * the list of executing child processes, free, and return its exit status.
478 * If there is no exited child, return -1.
481 */ 479 */
482static struct fsck_instance *wait_one(int flags) 480static int wait_one(int flags)
483{ 481{
484 int status; 482 int status;
485 int sig; 483 int sig;
@@ -487,46 +485,34 @@ static struct fsck_instance *wait_one(int flags)
487 pid_t pid; 485 pid_t pid;
488 486
489 if (!instance_list) 487 if (!instance_list)
490 return NULL; 488 return -1;
491 489 /* if (noexecute) { already returned -1; } */
492 if (noexecute) {
493 inst = instance_list;
494 prev = NULL;
495#ifdef RANDOM_DEBUG
496 while (inst->next && (random() & 1)) {
497 prev = inst;
498 inst = inst->next;
499 }
500#endif
501 inst->exit_status = 0;
502 goto ret_inst;
503 }
504 490
505 inst = prev = NULL; /* for gcc */ 491 while (1) {
506 do {
507 pid = waitpid(-1, &status, flags); 492 pid = waitpid(-1, &status, flags);
508 kill_all_if_cancel_requested(); 493 kill_all_if_cancel_requested();
509 if (pid == 0 && (flags & WNOHANG)) 494 if (pid == 0) /* flags == WNOHANG and no children exited */
510 return NULL; 495 return -1;
511 if (pid < 0) { 496 if (pid < 0) {
512 if (errno == EINTR || errno == EAGAIN) 497 if (errno == EINTR)
513 continue; 498 continue;
514 if (errno == ECHILD) { 499 if (errno == ECHILD) { /* paranoia */
515 bb_error_msg("wait: no more child process?!?"); 500 bb_error_msg("wait: no more children");
516 return NULL; 501 return -1;
517 } 502 }
518 bb_perror_msg("wait"); 503 bb_perror_msg("wait");
519 continue; 504 continue;
520 } 505 }
521 prev = NULL; 506 prev = NULL;
522 inst = instance_list; 507 inst = instance_list;
523 while (inst) { 508 do {
524 if (inst->pid == pid) 509 if (inst->pid == pid)
525 break; 510 goto child_died;
526 prev = inst; 511 prev = inst;
527 inst = inst->next; 512 inst = inst->next;
528 } 513 } while (inst);
529 } while (!inst); 514 }
515 child_died:
530 516
531 if (WIFEXITED(status)) 517 if (WIFEXITED(status))
532 status = WEXITSTATUS(status); 518 status = WEXITSTATUS(status);
@@ -534,8 +520,8 @@ static struct fsck_instance *wait_one(int flags)
534 sig = WTERMSIG(status); 520 sig = WTERMSIG(status);
535 status = EXIT_UNCORRECTED; 521 status = EXIT_UNCORRECTED;
536 if (sig != SIGINT) { 522 if (sig != SIGINT) {
537 printf("Warning... %s %s exited " 523 printf("Warning: %s %s terminated "
538 "with signal %d\n", 524 "by signal %d\n",
539 inst->prog, inst->device, sig); 525 inst->prog, inst->device, sig);
540 status = EXIT_ERROR; 526 status = EXIT_ERROR;
541 } 527 }
@@ -544,7 +530,6 @@ static struct fsck_instance *wait_one(int flags)
544 inst->prog, inst->device, status); 530 inst->prog, inst->device, status);
545 status = EXIT_ERROR; 531 status = EXIT_ERROR;
546 } 532 }
547 inst->exit_status = status;
548 533
549#if DO_PROGRESS_INDICATOR 534#if DO_PROGRESS_INDICATOR
550 if (progress && (inst->flags & FLAG_PROGRESS) && !progress_active()) { 535 if (progress && (inst->flags & FLAG_PROGRESS) && !progress_active()) {
@@ -573,39 +558,34 @@ static struct fsck_instance *wait_one(int flags)
573 } 558 }
574#endif 559#endif
575 560
576 ret_inst:
577 if (prev) 561 if (prev)
578 prev->next = inst->next; 562 prev->next = inst->next;
579 else 563 else
580 instance_list = inst->next; 564 instance_list = inst->next;
581 if (verbose > 1) 565 if (verbose > 1)
582 printf("Finished with %s (exit status %d)\n", 566 printf("Finished with %s (exit status %d)\n",
583 inst->device, inst->exit_status); 567 inst->device, status);
584 num_running--; 568 num_running--;
585 return inst; 569 free_instance(inst);
570
571 return status;
586} 572}
587 573
588#define FLAG_WAIT_ALL 0
589#define FLAG_WAIT_ATLEAST_ONE 1
590/* 574/*
591 * Wait until all executing child processes have exited; return the 575 * Wait until all executing child processes have exited; return the
592 * logical OR of all of their exit code values. 576 * logical OR of all of their exit code values.
593 */ 577 */
578#define FLAG_WAIT_ALL 0
579#define FLAG_WAIT_ATLEAST_ONE WNOHANG
594static int wait_many(int flags) 580static int wait_many(int flags)
595{ 581{
596 struct fsck_instance *inst; 582 int exit_status;
597 int global_status = 0; 583 int global_status = 0;
598 int wait_flags = 0; 584 int wait_flags = 0;
599 585
600 while ((inst = wait_one(wait_flags))) { 586 while ((exit_status = wait_one(wait_flags)) != -1) {
601 global_status |= inst->exit_status; 587 global_status |= exit_status;
602 free_instance(inst); 588 wait_flags |= flags;
603#ifdef RANDOM_DEBUG
604 if (noexecute && (flags & WNOHANG) && !(random() % 3))
605 break;
606#endif
607 if (flags & FLAG_WAIT_ATLEAST_ONE)
608 wait_flags = WNOHANG;
609 } 589 }
610 return global_status; 590 return global_status;
611} 591}
@@ -614,8 +594,8 @@ static int wait_many(int flags)
614 * Execute a particular fsck program, and link it into the list of 594 * Execute a particular fsck program, and link it into the list of
615 * child processes we are waiting for. 595 * child processes we are waiting for.
616 */ 596 */
617static void execute(const char *type, const char *device, const char *mntpt, 597static void execute(const char *type, const char *device,
618 int interactive) 598 const char *mntpt /*, int interactive */)
619{ 599{
620 char *argv[num_args + 4]; /* see count below: */ 600 char *argv[num_args + 4]; /* see count below: */
621 int argc; 601 int argc;
@@ -623,8 +603,6 @@ static void execute(const char *type, const char *device, const char *mntpt,
623 struct fsck_instance *inst; 603 struct fsck_instance *inst;
624 pid_t pid; 604 pid_t pid;
625 605
626 inst = xzalloc(sizeof(*inst));
627
628 argv[0] = xasprintf("fsck.%s", type); /* 1 */ 606 argv[0] = xasprintf("fsck.%s", type); /* 1 */
629 for (i = 0; i < num_args; i++) 607 for (i = 0; i < num_args; i++)
630 argv[i+1] = args[i]; /* num_args */ 608 argv[i+1] = args[i]; /* num_args */
@@ -641,7 +619,7 @@ static void execute(const char *type, const char *device, const char *mntpt,
641 } 619 }
642#endif 620#endif
643 621
644 argv[argc++] = xstrdup(device); /* 1 */ 622 argv[argc++] = (char*)device; /* 1 */
645 argv[argc] = NULL; /* 1 */ 623 argv[argc] = NULL; /* 1 */
646 624
647 if (verbose || noexecute) { 625 if (verbose || noexecute) {
@@ -660,21 +638,24 @@ static void execute(const char *type, const char *device, const char *mntpt,
660 bb_simple_perror_msg(argv[0]); 638 bb_simple_perror_msg(argv[0]);
661 } 639 }
662 640
663 for (i = num_args+1; i < argc; i++) 641#if DO_PROGRESS_INDICATOR
664 free(argv[i]); 642 free(argv[num_args + 1]);
643#endif
665 644
666 /* No pid, so don't record an instance */ 645 /* No child, so don't record an instance */
667 if (pid < 0) { 646 if (pid <= 0) {
668 free(inst); 647 free(argv[0]);
669 return; 648 return;
670 } 649 }
671 650
651 inst = xzalloc(sizeof(*inst));
672 inst->pid = pid; 652 inst->pid = pid;
673 inst->prog = argv[0]; 653 inst->prog = argv[0];
674 inst->type = xstrdup(type);
675 inst->device = xstrdup(device); 654 inst->device = xstrdup(device);
676 inst->base_device = base_device(device); 655 inst->base_device = base_device(device);
656#if DO_PROGRESS_INDICATOR
677 inst->start_time = time(NULL); 657 inst->start_time = time(NULL);
658#endif
678 659
679 /* Add to the list of running fsck's. 660 /* Add to the list of running fsck's.
680 * (was adding to the end, but adding to the front is simpler...) */ 661 * (was adding to the end, but adding to the front is simpler...) */
@@ -692,7 +673,7 @@ static void execute(const char *type, const char *device, const char *mntpt,
692 * If the type isn't specified by the user, then use either the type 673 * If the type isn't specified by the user, then use either the type
693 * specified in /etc/fstab, or "auto". 674 * specified in /etc/fstab, or "auto".
694 */ 675 */
695static void fsck_device(struct fs_info *fs, int interactive) 676static void fsck_device(struct fs_info *fs /*, int interactive */)
696{ 677{
697 const char *type; 678 const char *type;
698 679
@@ -719,7 +700,7 @@ static void fsck_device(struct fs_info *fs, int interactive)
719 } 700 }
720 701
721 num_running++; 702 num_running++;
722 execute(type, fs->device, fs->mountpt, interactive); 703 execute(type, fs->device, fs->mountpt /*, interactive */);
723} 704}
724 705
725/* 706/*
@@ -871,32 +852,31 @@ static int check_all(void)
871 * which should be ignored as done, and resolve any "auto" 852 * which should be ignored as done, and resolve any "auto"
872 * filesystem types (done as a side-effect of calling ignore()). 853 * filesystem types (done as a side-effect of calling ignore()).
873 */ 854 */
874 for (fs = filesys_info; fs; fs = fs->next) { 855 for (fs = filesys_info; fs; fs = fs->next)
875 if (ignore(fs)) 856 if (ignore(fs))
876 fs->flags |= FLAG_DONE; 857 fs->flags |= FLAG_DONE;
877 }
878 858
879 /* 859 /*
880 * Find and check the root filesystem. 860 * Find and check the root filesystem.
881 */ 861 */
882 if (!parallel_root) { 862 if (!parallel_root) {
883 for (fs = filesys_info; fs; fs = fs->next) { 863 for (fs = filesys_info; fs; fs = fs->next) {
884 if (LONE_CHAR(fs->mountpt, '/')) 864 if (LONE_CHAR(fs->mountpt, '/')) {
865 if (!skip_root && !ignore(fs)) {
866 fsck_device(fs /*, 1*/);
867 status |= wait_many(FLAG_WAIT_ALL);
868 if (status > EXIT_NONDESTRUCT)
869 return status;
870 }
871 fs->flags |= FLAG_DONE;
885 break; 872 break;
886 }
887 if (fs) {
888 if (!skip_root && !ignore(fs)) {
889 fsck_device(fs, 1);
890 status |= wait_many(FLAG_WAIT_ALL);
891 if (status > EXIT_NONDESTRUCT)
892 return status;
893 } 873 }
894 fs->flags |= FLAG_DONE;
895 } 874 }
896 } 875 }
897 /* 876 /*
898 * This is for the bone-headed user who enters the root 877 * This is for the bone-headed user who has root
899 * filesystem twice. Skip root will skip all root entries. 878 * filesystem listed twice.
879 * "Skip root" will skip _all_ root entries.
900 */ 880 */
901 if (skip_root) 881 if (skip_root)
902 for (fs = filesys_info; fs; fs = fs->next) 882 for (fs = filesys_info; fs; fs = fs->next)
@@ -916,7 +896,7 @@ static int check_all(void)
916 continue; 896 continue;
917 /* 897 /*
918 * If the filesystem's pass number is higher 898 * If the filesystem's pass number is higher
919 * than the current pass number, then we don't 899 * than the current pass number, then we didn't
920 * do it yet. 900 * do it yet.
921 */ 901 */
922 if (fs->passno > passno) { 902 if (fs->passno > passno) {
@@ -935,7 +915,7 @@ static int check_all(void)
935 /* 915 /*
936 * Spawn off the fsck process 916 * Spawn off the fsck process
937 */ 917 */
938 fsck_device(fs, serialize); 918 fsck_device(fs /*, serialize*/);
939 fs->flags |= FLAG_DONE; 919 fs->flags |= FLAG_DONE;
940 920
941 /* 921 /*
@@ -979,21 +959,16 @@ static void compile_fs_type(char *fs_type)
979 int num = 2; 959 int num = 2;
980 smallint negate; 960 smallint negate;
981 961
982 if (fs_type) { 962 s = fs_type;
983 s = fs_type; 963 while ((s = strchr(s, ','))) {
984 while ((s = strchr(s, ','))) { 964 num++;
985 num++; 965 s++;
986 s++;
987 }
988 } 966 }
989 967
990 fs_type_list = xzalloc(num * sizeof(fs_type_list[0])); 968 fs_type_list = xzalloc(num * sizeof(fs_type_list[0]));
991 fs_type_flag = xzalloc(num * sizeof(fs_type_flag[0])); 969 fs_type_flag = xzalloc(num * sizeof(fs_type_flag[0]));
992 fs_type_negated = -1; /* not yet known is it negated or not */ 970 fs_type_negated = -1; /* not yet known is it negated or not */
993 971
994 if (!fs_type)
995 return;
996
997 num = 0; 972 num = 0;
998 s = fs_type; 973 s = fs_type;
999 while (1) { 974 while (1) {
@@ -1031,12 +1006,12 @@ static void compile_fs_type(char *fs_type)
1031 } 1006 }
1032} 1007}
1033 1008
1034static void parse_args(int argc, char **argv) 1009static void parse_args(char **argv)
1035{ 1010{
1036 int i, j; 1011 int i, j;
1037 char *arg, *tmp; 1012 char *arg, *tmp;
1038 char *options = NULL; 1013 char *options;
1039 int optpos = 0; 1014 int optpos;
1040 int opts_for_fsck = 0; 1015 int opts_for_fsck = 0;
1041 1016
1042 /* in bss, so already zeroed 1017 /* in bss, so already zeroed
@@ -1045,8 +1020,7 @@ static void parse_args(int argc, char **argv)
1045 instance_list = NULL; 1020 instance_list = NULL;
1046 */ 1021 */
1047 1022
1048/* TODO: getopt32 */ 1023 for (i = 1; argv[i]; i++) {
1049 for (i = 1; i < argc; i++) {
1050 arg = argv[i]; 1024 arg = argv[i];
1051 1025
1052 /* "/dev/blk" or "/path" or "UUID=xxx" or "LABEL=xxx" */ 1026 /* "/dev/blk" or "/path" or "UUID=xxx" or "LABEL=xxx" */
@@ -1065,14 +1039,14 @@ static void parse_args(int argc, char **argv)
1065 continue; 1039 continue;
1066 } 1040 }
1067 1041
1042 if (LONE_CHAR(arg + 1, '-')) { /* "--" ? */
1043 opts_for_fsck = 1;
1044 continue;
1045 }
1046
1047 optpos = 0;
1048 options = NULL;
1068 for (j = 1; arg[j]; j++) { 1049 for (j = 1; arg[j]; j++) {
1069 if (opts_for_fsck) {
1070 optpos++;
1071 /* one extra for '\0' */
1072 options = xrealloc(options, optpos + 2);
1073 options[optpos] = arg[j];
1074 continue;
1075 }
1076 switch (arg[j]) { 1050 switch (arg[j]) {
1077 case 'A': 1051 case 'A':
1078 doall = 1; 1052 doall = 1;
@@ -1085,7 +1059,8 @@ static void parse_args(int argc, char **argv)
1085 goto next_arg; 1059 goto next_arg;
1086 } 1060 }
1087 /* -C n */ 1061 /* -C n */
1088 progress_fd = xatoi_u(argv[++i]); 1062 if (!argv[++i]) bb_show_usage();
1063 progress_fd = xatoi_u(argv[i]);
1089 goto next_arg; 1064 goto next_arg;
1090#endif 1065#endif
1091 case 'V': 1066 case 'V':
@@ -1114,16 +1089,13 @@ static void parse_args(int argc, char **argv)
1114 bb_show_usage(); 1089 bb_show_usage();
1115 if (arg[++j]) 1090 if (arg[++j])
1116 tmp = &arg[j]; 1091 tmp = &arg[j];
1117 else if (++i < argc) 1092 else if (argv[++i])
1118 tmp = argv[i]; 1093 tmp = argv[i];
1119 else 1094 else
1120 bb_show_usage(); 1095 bb_show_usage();
1121 fstype = xstrdup(tmp); 1096 fstype = xstrdup(tmp);
1122 compile_fs_type(fstype); 1097 compile_fs_type(fstype);
1123 goto next_arg; 1098 goto next_arg;
1124 case '-':
1125 opts_for_fsck++;
1126 break;
1127 case '?': 1099 case '?':
1128 bb_show_usage(); 1100 bb_show_usage();
1129 break; 1101 break;
@@ -1141,8 +1113,6 @@ static void parse_args(int argc, char **argv)
1141 options[optpos + 1] = '\0'; 1113 options[optpos + 1] = '\0';
1142 args = xrealloc(args, (num_args+1) * sizeof(args[0])); 1114 args = xrealloc(args, (num_args+1) * sizeof(args[0]));
1143 args[num_args++] = options; 1115 args[num_args++] = options;
1144 optpos = 0;
1145 options = NULL;
1146 } 1116 }
1147 } 1117 }
1148 if (getenv("FSCK_FORCE_ALL_PARALLEL")) 1118 if (getenv("FSCK_FORCE_ALL_PARALLEL"))
@@ -1160,17 +1130,18 @@ static void signal_cancel(int sig ATTRIBUTE_UNUSED)
1160int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1130int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1161int fsck_main(int argc, char **argv) 1131int fsck_main(int argc, char **argv)
1162{ 1132{
1163 int i, status = 0; 1133 int i, status;
1164 int interactive; 1134 /*int interactive;*/
1165 const char *fstab; 1135 const char *fstab;
1166 struct fs_info *fs; 1136 struct fs_info *fs;
1167 1137
1138 /* we want wait() to be interruptible */
1168 signal_no_SA_RESTART_empty_mask(SIGINT, signal_cancel); 1139 signal_no_SA_RESTART_empty_mask(SIGINT, signal_cancel);
1169 signal_no_SA_RESTART_empty_mask(SIGTERM, signal_cancel); 1140 signal_no_SA_RESTART_empty_mask(SIGTERM, signal_cancel);
1170 1141
1171 setbuf(stdout, NULL); 1142 setbuf(stdout, NULL);
1172 1143
1173 parse_args(argc, argv); 1144 parse_args(argv);
1174 1145
1175 if (!notitle) 1146 if (!notitle)
1176 puts("fsck (busybox "BB_VER", "BB_BT")"); 1147 puts("fsck (busybox "BB_VER", "BB_BT")");
@@ -1182,18 +1153,14 @@ int fsck_main(int argc, char **argv)
1182 fstab = "/etc/fstab"; 1153 fstab = "/etc/fstab";
1183 load_fs_info(fstab); 1154 load_fs_info(fstab);
1184 1155
1185 interactive = (num_devices == 1) | serialize; 1156 /*interactive = (num_devices == 1) | serialize;*/
1186 1157
1187 /* If -A was specified ("check all"), do that! */ 1158 if (num_devices == 0)
1159 /*interactive =*/ serialize = doall = 1;
1188 if (doall) 1160 if (doall)
1189 return check_all(); 1161 return check_all();
1190 1162
1191 if (num_devices == 0) { 1163 status = 0;
1192 serialize = 1;
1193 interactive = 1;
1194 return check_all();
1195 }
1196
1197 for (i = 0; i < num_devices; i++) { 1164 for (i = 0; i < num_devices; i++) {
1198 if (cancel_requested) { 1165 if (cancel_requested) {
1199 kill_all_if_cancel_requested(); 1166 kill_all_if_cancel_requested();
@@ -1202,19 +1169,15 @@ int fsck_main(int argc, char **argv)
1202 1169
1203 fs = lookup(devices[i]); 1170 fs = lookup(devices[i]);
1204 if (!fs) 1171 if (!fs)
1205 fs = create_fs_device(devices[i], 0, "auto", 0, -1, -1); 1172 fs = create_fs_device(devices[i], "", "auto", NULL, -1);
1206 fsck_device(fs, interactive); 1173 fsck_device(fs /*, interactive */);
1207 1174
1208 if (serialize 1175 if (serialize
1209 || (max_running && (num_running >= max_running)) 1176 || (max_running && (num_running >= max_running))
1210 ) { 1177 ) {
1211 struct fsck_instance *inst; 1178 int exit_status = wait_one(0);
1212 1179 if (exit_status >= 0)
1213 inst = wait_one(0); 1180 status |= exit_status;
1214 if (inst) {
1215 status |= inst->exit_status;
1216 free_instance(inst);
1217 }
1218 if (verbose > 1) 1181 if (verbose > 1)
1219 puts("----------------------------------"); 1182 puts("----------------------------------");
1220 } 1183 }