init: fix askfirst not working as intended

This commit is contained in:
Denis Vlasenko 2008-04-05 04:24:23 +00:00
parent 0a38bcf570
commit ad4da989e3

View File

@ -33,14 +33,15 @@
#endif #endif
/* Allowed init action types */ /* Allowed init action types */
#define SYSINIT 0x001 #define SYSINIT 0x01
#define RESPAWN 0x002 #define RESPAWN 0x02
#define ASKFIRST 0x004 /* like respawn, but wait for <Enter> to be pressed on tty: */
#define WAIT 0x008 #define ASKFIRST 0x04
#define ONCE 0x010 #define WAIT 0x08
#define CTRLALTDEL 0x020 #define ONCE 0x10
#define SHUTDOWN 0x040 #define CTRLALTDEL 0x20
#define RESTART 0x080 #define SHUTDOWN 0x40
#define RESTART 0x80
#define STR_SYSINIT "\x01" #define STR_SYSINIT "\x01"
#define STR_RESPAWN "\x02" #define STR_RESPAWN "\x02"
@ -372,6 +373,9 @@ static pid_t run(const struct init_action *a)
sigemptyset(&nmask); sigemptyset(&nmask);
sigaddset(&nmask, SIGCHLD); sigaddset(&nmask, SIGCHLD);
sigprocmask(SIG_BLOCK, &nmask, &omask); sigprocmask(SIG_BLOCK, &nmask, &omask);
if (BB_MMU && (a->action_type & ASKFIRST))
pid = fork();
else
pid = vfork(); pid = vfork();
sigprocmask(SIG_SETMASK, &omask, NULL); sigprocmask(SIG_SETMASK, &omask, NULL);
@ -447,7 +451,8 @@ static pid_t run(const struct init_action *a)
} }
#endif #endif
/* NB: on NOMMU we can't wait for input in child */ /* NB: on NOMMU we can't wait for input in child, so
* "askfirst" will work the same as "respawn". */
if (BB_MMU && (a->action_type & ASKFIRST)) { if (BB_MMU && (a->action_type & ASKFIRST)) {
static const char press_enter[] ALIGN1 = static const char press_enter[] ALIGN1 =
#ifdef CUSTOMIZED_BANNER #ifdef CUSTOMIZED_BANNER
@ -499,7 +504,7 @@ static void run_actions(int action_type)
for (a = init_action_list; a; a = tmp) { for (a = init_action_list; a; a = tmp) {
tmp = a->next; tmp = a->next;
if (a->action_type == action_type) { if (a->action_type & action_type) {
// Pointless: run() will error out if open of device fails. // Pointless: run() will error out if open of device fails.
///* a->terminal of "" means "init's console" */ ///* a->terminal of "" means "init's console" */
//if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) { //if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) {
@ -784,6 +789,7 @@ static void parse_inittab(void)
fclose(file); fclose(file);
} }
#if ENABLE_FEATURE_USE_INITTAB
static void reload_signal(int sig ATTRIBUTE_UNUSED) static void reload_signal(int sig ATTRIBUTE_UNUSED)
{ {
struct init_action *a, *tmp; struct init_action *a, *tmp;
@ -827,8 +833,9 @@ static void reload_signal(int sig ATTRIBUTE_UNUSED)
delete_init_action(a); delete_init_action(a);
} }
} }
run_actions(RESPAWN); run_actions(RESPAWN | ASKFIRST);
} }
#endif
int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int init_main(int argc ATTRIBUTE_UNUSED, char **argv) int init_main(int argc ATTRIBUTE_UNUSED, char **argv)
@ -952,18 +959,16 @@ int init_main(int argc ATTRIBUTE_UNUSED, char **argv)
run_actions(ONCE); run_actions(ONCE);
/* Redefine SIGHUP to reread /etc/inittab */ /* Redefine SIGHUP to reread /etc/inittab */
if (ENABLE_FEATURE_USE_INITTAB) #if ENABLE_FEATURE_USE_INITTAB
signal(SIGHUP, reload_signal); signal(SIGHUP, reload_signal);
else #else
signal(SIGHUP, SIG_IGN); signal(SIGHUP, SIG_IGN);
#endif
/* Now run the looping stuff for the rest of forever */ /* Now run the looping stuff for the rest of forever */
while (1) { while (1) {
/* run the respawn stuff */ /* run the respawn/askfirst stuff */
run_actions(RESPAWN); run_actions(RESPAWN | ASKFIRST);
/* run the askfirst stuff */
run_actions(ASKFIRST);
/* Don't consume all CPU time -- sleep a bit */ /* Don't consume all CPU time -- sleep a bit */
sleep(1); sleep(1);