On Friday 04 April 2008 22:40, Harald Kuethe wrote:
> The first part is with a vfork() call in static pid_t run(const struct 
> init_action *a) 
> the second part uses fork()
> 
> Freeing unused kernel memory: 68k init
> *Start init_main
> init: waiting for 10
> *console_init
> init started
> init started: BusyBox v1.10.0 (2008-04-01 22:01:03 CEST)
> *single?
> *run_actions
> init: before waitfor(run(a))
> init: run vfork returned 0
> init: run vfork returned 11
> *call bb_signals
> init: waiting for 11
> 
> ...
> 
> init: after waitfor(run(a))
> *signals
> *RESPAWN
> *ASKFIRST
> init: before a->pid = run(a)
> init: run vfork returned 0
> 
> Please press Enter to activate this console.
> init: run vfork returned 80



        if (BB_MMU && (a->action_type & ASKFIRST)) {
                static const char press_enter[] ALIGN1 =
#ifdef CUSTOMIZED_BANNER
#include CUSTOMIZED_BANNER
#endif
                        "\nPlease press Enter to activate this console. ";
                char c;
                /*
                 * Save memory by not exec-ing anything large (like a shell)
                 * before the user wants it. This is critical if swap is not
                 * enabled and the system has low memory. Generally this will
                 * be run on the second virtual console, and the first will
                 * be allowed to start a shell or whatever an init script
                 * specifies.
                 */
                messageD(L_LOG, "waiting for enter to start '%s'"
                                        "(pid %d, tty '%s')\n",
                                a->command, getpid(), a->terminal);
                full_write(1, press_enter, sizeof(press_enter) - 1);
                while (safe_read(0, &c, 1) == 1 && c != '\n')
                        continue;
        }


DOH!

Try this patch.
--
vda
diff -d -urpN busybox.9/init/init.c busybox.a/init/init.c
--- busybox.9/init/init.c	2008-03-31 21:26:19.000000000 +0200
+++ busybox.a/init/init.c	2008-04-05 06:22:35.000000000 +0200
@@ -33,14 +33,15 @@
 #endif
 
 /* Allowed init action types */
-#define SYSINIT     0x001
-#define RESPAWN     0x002
-#define ASKFIRST    0x004
-#define WAIT        0x008
-#define ONCE        0x010
-#define CTRLALTDEL  0x020
-#define SHUTDOWN    0x040
-#define RESTART     0x080
+#define SYSINIT     0x01
+#define RESPAWN     0x02
+/* like respawn, but wait for <Enter> to be pressed on tty: */
+#define ASKFIRST    0x04
+#define WAIT        0x08
+#define ONCE        0x10
+#define CTRLALTDEL  0x20
+#define SHUTDOWN    0x40
+#define RESTART     0x80
 
 #define STR_SYSINIT     "\x01"
 #define STR_RESPAWN     "\x02"
@@ -372,7 +373,10 @@ static pid_t run(const struct init_actio
 	sigemptyset(&nmask);
 	sigaddset(&nmask, SIGCHLD);
 	sigprocmask(SIG_BLOCK, &nmask, &omask);
-	pid = vfork();
+	if (BB_MMU && (a->action_type & ASKFIRST))
+		pid = fork();
+	else
+		pid = vfork();
 	sigprocmask(SIG_SETMASK, &omask, NULL);
 
 	if (pid < 0)
@@ -447,7 +451,8 @@ static pid_t run(const struct init_actio
 	}
 #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)) {
 		static const char press_enter[] ALIGN1 =
 #ifdef CUSTOMIZED_BANNER
@@ -499,7 +504,7 @@ static void run_actions(int action_type)
 
 	for (a = init_action_list; a; a = tmp) {
 		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.
 			///* a->terminal of "" means "init's console" */
 			//if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) {
@@ -784,6 +789,7 @@ static void parse_inittab(void)
 	fclose(file);
 }
 
+#if ENABLE_FEATURE_USE_INITTAB
 static void reload_signal(int sig ATTRIBUTE_UNUSED)
 {
 	struct init_action *a, *tmp;
@@ -827,8 +833,9 @@ static void reload_signal(int sig ATTRIB
 			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 ATTRIBUTE_UNUSED, char **argv)
@@ -952,18 +959,16 @@ int init_main(int argc ATTRIBUTE_UNUSED,
 	run_actions(ONCE);
 
 	/* Redefine SIGHUP to reread /etc/inittab */
-	if (ENABLE_FEATURE_USE_INITTAB)
-		signal(SIGHUP, reload_signal);
-	else
-		signal(SIGHUP, SIG_IGN);
+#if ENABLE_FEATURE_USE_INITTAB
+	signal(SIGHUP, reload_signal);
+#else
+	signal(SIGHUP, SIG_IGN);
+#endif
 
 	/* Now run the looping stuff for the rest of forever */
 	while (1) {
-		/* run the respawn stuff */
-		run_actions(RESPAWN);
-
-		/* run the askfirst stuff */
-		run_actions(ASKFIRST);
+		/* run the respawn/askfirst stuff */
+		run_actions(RESPAWN | ASKFIRST);
 
 		/* Don't consume all CPU time -- sleep a bit */
 		sleep(1);
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to