diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-05 04:24:23 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-05 04:24:23 +0000 |
commit | ad4da989e3767cdf4620725c16908b4f99dbe2c9 (patch) | |
tree | 11f5c13d7dd6d973ab4a0becab85a8d1903d4edf | |
parent | 0a38bcf570b88deb6c71f850c12ff1b9a31a9bd9 (diff) | |
download | busybox-w32-ad4da989e3767cdf4620725c16908b4f99dbe2c9.tar.gz busybox-w32-ad4da989e3767cdf4620725c16908b4f99dbe2c9.tar.bz2 busybox-w32-ad4da989e3767cdf4620725c16908b4f99dbe2c9.zip |
init: fix askfirst not working as intended
-rw-r--r-- | init/init.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/init/init.c b/init/init.c index 61b302556..e2fde5f23 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -33,14 +33,15 @@ | |||
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | /* Allowed init action types */ | 35 | /* Allowed init action types */ |
36 | #define SYSINIT 0x001 | 36 | #define SYSINIT 0x01 |
37 | #define RESPAWN 0x002 | 37 | #define RESPAWN 0x02 |
38 | #define ASKFIRST 0x004 | 38 | /* like respawn, but wait for <Enter> to be pressed on tty: */ |
39 | #define WAIT 0x008 | 39 | #define ASKFIRST 0x04 |
40 | #define ONCE 0x010 | 40 | #define WAIT 0x08 |
41 | #define CTRLALTDEL 0x020 | 41 | #define ONCE 0x10 |
42 | #define SHUTDOWN 0x040 | 42 | #define CTRLALTDEL 0x20 |
43 | #define RESTART 0x080 | 43 | #define SHUTDOWN 0x40 |
44 | #define RESTART 0x80 | ||
44 | 45 | ||
45 | #define STR_SYSINIT "\x01" | 46 | #define STR_SYSINIT "\x01" |
46 | #define STR_RESPAWN "\x02" | 47 | #define STR_RESPAWN "\x02" |
@@ -372,7 +373,10 @@ static pid_t run(const struct init_action *a) | |||
372 | sigemptyset(&nmask); | 373 | sigemptyset(&nmask); |
373 | sigaddset(&nmask, SIGCHLD); | 374 | sigaddset(&nmask, SIGCHLD); |
374 | sigprocmask(SIG_BLOCK, &nmask, &omask); | 375 | sigprocmask(SIG_BLOCK, &nmask, &omask); |
375 | pid = vfork(); | 376 | if (BB_MMU && (a->action_type & ASKFIRST)) |
377 | pid = fork(); | ||
378 | else | ||
379 | pid = vfork(); | ||
376 | sigprocmask(SIG_SETMASK, &omask, NULL); | 380 | sigprocmask(SIG_SETMASK, &omask, NULL); |
377 | 381 | ||
378 | if (pid < 0) | 382 | if (pid < 0) |
@@ -447,7 +451,8 @@ static pid_t run(const struct init_action *a) | |||
447 | } | 451 | } |
448 | #endif | 452 | #endif |
449 | 453 | ||
450 | /* NB: on NOMMU we can't wait for input in child */ | 454 | /* NB: on NOMMU we can't wait for input in child, so |
455 | * "askfirst" will work the same as "respawn". */ | ||
451 | if (BB_MMU && (a->action_type & ASKFIRST)) { | 456 | if (BB_MMU && (a->action_type & ASKFIRST)) { |
452 | static const char press_enter[] ALIGN1 = | 457 | static const char press_enter[] ALIGN1 = |
453 | #ifdef CUSTOMIZED_BANNER | 458 | #ifdef CUSTOMIZED_BANNER |
@@ -499,7 +504,7 @@ static void run_actions(int action_type) | |||
499 | 504 | ||
500 | for (a = init_action_list; a; a = tmp) { | 505 | for (a = init_action_list; a; a = tmp) { |
501 | tmp = a->next; | 506 | tmp = a->next; |
502 | if (a->action_type == action_type) { | 507 | if (a->action_type & action_type) { |
503 | // Pointless: run() will error out if open of device fails. | 508 | // Pointless: run() will error out if open of device fails. |
504 | ///* a->terminal of "" means "init's console" */ | 509 | ///* a->terminal of "" means "init's console" */ |
505 | //if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) { | 510 | //if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) { |
@@ -784,6 +789,7 @@ static void parse_inittab(void) | |||
784 | fclose(file); | 789 | fclose(file); |
785 | } | 790 | } |
786 | 791 | ||
792 | #if ENABLE_FEATURE_USE_INITTAB | ||
787 | static void reload_signal(int sig ATTRIBUTE_UNUSED) | 793 | static void reload_signal(int sig ATTRIBUTE_UNUSED) |
788 | { | 794 | { |
789 | struct init_action *a, *tmp; | 795 | struct init_action *a, *tmp; |
@@ -827,8 +833,9 @@ static void reload_signal(int sig ATTRIBUTE_UNUSED) | |||
827 | delete_init_action(a); | 833 | delete_init_action(a); |
828 | } | 834 | } |
829 | } | 835 | } |
830 | run_actions(RESPAWN); | 836 | run_actions(RESPAWN | ASKFIRST); |
831 | } | 837 | } |
838 | #endif | ||
832 | 839 | ||
833 | int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 840 | int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
834 | int init_main(int argc ATTRIBUTE_UNUSED, char **argv) | 841 | int init_main(int argc ATTRIBUTE_UNUSED, char **argv) |
@@ -952,18 +959,16 @@ int init_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
952 | run_actions(ONCE); | 959 | run_actions(ONCE); |
953 | 960 | ||
954 | /* Redefine SIGHUP to reread /etc/inittab */ | 961 | /* Redefine SIGHUP to reread /etc/inittab */ |
955 | if (ENABLE_FEATURE_USE_INITTAB) | 962 | #if ENABLE_FEATURE_USE_INITTAB |
956 | signal(SIGHUP, reload_signal); | 963 | signal(SIGHUP, reload_signal); |
957 | else | 964 | #else |
958 | signal(SIGHUP, SIG_IGN); | 965 | signal(SIGHUP, SIG_IGN); |
966 | #endif | ||
959 | 967 | ||
960 | /* Now run the looping stuff for the rest of forever */ | 968 | /* Now run the looping stuff for the rest of forever */ |
961 | while (1) { | 969 | while (1) { |
962 | /* run the respawn stuff */ | 970 | /* run the respawn/askfirst stuff */ |
963 | run_actions(RESPAWN); | 971 | run_actions(RESPAWN | ASKFIRST); |
964 | |||
965 | /* run the askfirst stuff */ | ||
966 | run_actions(ASKFIRST); | ||
967 | 972 | ||
968 | /* Don't consume all CPU time -- sleep a bit */ | 973 | /* Don't consume all CPU time -- sleep a bit */ |
969 | sleep(1); | 974 | sleep(1); |