[BusyBox] Init-Problems with halt; the final

Martin Sieper msi at ngi-box.de
Thu Feb 21 15:49:03 UTC 2002


Hi,

in the past other people and I had a problem with BusyBox' 
halt-command. The kernel say

Kernel panic: attempt to kill init

after shutdown the system. Now I've made a patch to fix this.
I don't know if this the right way but it works fine for me.
Please take a look on my patch in the attachment.

  -Martin

P.S. I'm using busybox 0.60.2
-------------- next part --------------
--- init.c.orig	Tue Nov 20 06:43:28 2001
+++ init.c	Thu Feb 14 14:33:04 2002
@@ -660,12 +660,12 @@
 	sync();
 
 	/* Send signals to every process _except_ pid 1 */
-	message(CONSOLE|LOG, "Sending SIGTERM to all processes.\n");
+	message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n");
 	kill(-1, SIGTERM);
 	sleep(1);
 	sync();
 
-	message(CONSOLE|LOG, "Sending SIGKILL to all processes.\n");
+	message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n");
 	kill(-1, SIGKILL);
 	sleep(1);
 
@@ -682,6 +682,8 @@
 
 static void halt_signal(int sig)
 {
+	int pid;
+
 	shutdown_system();
 	message(CONSOLE|LOG,
 #if #cpu(s390)
@@ -689,7 +691,7 @@
 			"The system is halted. You may reboot now.\n",
 #else
 			/* secondConsole is NULL for a serial console */
-			"The system is halted. Press %s or turn off power\n",
+			"\rThe system is halted. Press %s or turn off power\n",
 			(secondConsole == NULL)? "Reset" : "CTRL-ALT-DEL"
 #endif
 		   );
@@ -698,12 +700,27 @@
 	/* allow time for last message to reach serial console */
 	sleep(2);
 
-	if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2,2,0))
-		init_reboot(RB_POWER_OFF);
-	else
-		init_reboot(RB_HALT_SYSTEM);
-
-	loop_forever();
+	if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2,2,0)) {
+		pid = fork();
+		if (pid < 0) {
+			fprintf(stderr, "init: fork() error\n");
+		} else if (pid == 0) {
+			setsid();
+			init_reboot(RB_POWER_OFF);
+		} else if (pid > 0) {
+			loop_forever();
+		}
+	} else {
+		pid = fork();
+		if (pid < 0) {
+			fprintf(stderr, "init: fork() error\n");
+		} else if (pid == 0) {
+			setsid();
+			init_reboot(RB_HALT_SYSTEM);
+		} else if (pid > 0) {
+			loop_forever();
+		}
+	}
 }
 
 static void reboot_signal(int sig)


More information about the busybox mailing list