[BusyBox-cvs] busybox.stable init.c,1.178,1.179

Erik Andersen andersen at busybox.net
Sat Jul 5 08:28:42 UTC 2003


Update of /var/cvs/busybox.stable
In directory winder:/tmp/cvs-serv15606

Modified Files:
	init.c 
Log Message:
Daniel writes:

I've found a problem with job control when the init process is restarted.

If the system boots for the first time, I get job control on a serial terminal -
no problems. However, when I restart init by issuing "init -q", then the shell
no longer has job control.

I traced this a problem in console_init in the file init.c. What was happening
after the restart is that the first compare

    if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
	...
    } else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
	...
    } else {
	... // assume /dev/console
    }

returned error and subsequently the code assumes /dev/console as the console,
which does not support job control.

Checking the errno after the first call showed that the system was complaining
about the file descriptor. This is probably because the previous init process
had closed all its file descriptors which the new init process had inherited.



Index: init.c
===================================================================
RCS file: /var/cvs/busybox.stable/init.c,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -d -r1.178 -r1.179
--- init.c	27 Jun 2003 05:44:33 -0000	1.178
+++ init.c	5 Jul 2003 08:28:38 -0000	1.179
@@ -696,7 +696,7 @@
 {
 	pid_t pid;
 	/* We have to fork here, since the kernel calls do_exit(0) in
-	 * linux/kernel/sys.c, which can cause the machint to panic when 
+	 * linux/kernel/sys.c, which can cause the machine to panic when 
 	 * the init process is killed.... */
 	if ((pid = fork()) == 0) {
 #if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__)
@@ -779,6 +779,22 @@
 			sigaddset(&unblock_signals, SIGSTOP);
 			sigaddset(&unblock_signals, SIGTSTP);
 			sigprocmask(SIG_UNBLOCK, &unblock_signals, NULL);
+
+			/* Open the new terminal device */
+			if ((device_open(a->terminal, O_RDWR)) < 0) {
+				if (stat(a->terminal, &sb) != 0) {
+					message(LOG | CONSOLE, "device '%s' does not exist.", a->terminal);
+				} else {
+					message(LOG | CONSOLE, "Bummer, can't open %s", a->terminal);
+				}
+				halt_signal(SIGUSR1);
+			}
+
+			/* Make sure the terminal will act fairly normal for us */
+			set_term(0);
+			/* Setup stdout, stderr on the supplied terminal */
+			dup(0);
+			dup(0);
 
 			message(CONSOLE|LOG, "\rTrying to re-exec %s\n", a->command);
 			execl(a->command, a->command, NULL);




More information about the busybox-cvs mailing list