[BusyBox] init and serial consoles

Tim Riker Tim at Rikers.org
Sat Jul 27 20:27:03 UTC 2002


I know it's been asked on this list before like on:

http://busybox.net/lists/busybox/2002-July/011887.html

and it was bugging me again, so I patched init to check for each device
and only if the device does not exist, to refuse to start an inittab
entry.

Serial console does not prevent you askfirst and respawn gettys on other
virtual consoles, but turning off virtual console support in the kernel
does. This seem to work fine for me on the current board I'm testing. I
sent the patch to (swamped) Erik, but he did not get a chance to review
it, so here it is for public review.
-- 
Tim Riker - http://rikers.org/ - TimR at Debian.org
Lineo CTO - Tim at Lineo.com - http://www.Lineo.com/
BZFlag maintainer - http://BZFlag.org/ - for fun!
-------------- next part --------------
? busybox-consoles.diff
Index: Changelog
===================================================================
RCS file: /var/cvs/busybox/Changelog,v
retrieving revision 1.276
diff -u -u -r1.276 Changelog
--- Changelog	1 May 2002 05:57:15 -0000	1.276
+++ Changelog	18 Jul 2002 09:55:40 -0000
@@ -33,7 +33,8 @@
 		uClibc, fix route crashe 'route add', fix warnings compile
 		networking and pwd_grp applets
 	* Tim Riker <Tim at Rikers.org>
-		-- fix and shrink uuencode
+	    -- fix and shrink uuencode
+	    -- allow tty* in inittab if exist, serial console is not the issue
 
 	 -Erik Andersen, --not yet released--
 
Index: init/init.c
===================================================================
RCS file: /var/cvs/busybox/init/init.c,v
retrieving revision 1.165
diff -u -u -r1.165 init.c
--- init/init.c	3 Jul 2002 23:49:27 -0000	1.165
+++ init/init.c	18 Jul 2002 09:55:41 -0000
@@ -159,10 +159,6 @@
 
 /* Static variables */
 static struct init_action *init_action_list = NULL;
-static char *secondConsole = VC_2;
-static char *thirdConsole  = VC_3;
-static char *fourthConsole = VC_4;
-static char *log           = VC_5;
 static int  kernelVersion  = 0;
 static char termType[32]   = "TERM=linux";
 static char console[32]    = _PATH_CONSOLE;
@@ -223,15 +219,9 @@
 	/* Take full control of the log tty, and never close it.
 	 * It's mine, all mine!  Muhahahaha! */
 	if (log_fd < 0) {
-		if (log == NULL) {
-			/* don't even try to log, because there is no such console */
+		if ((log_fd = device_open(VC_5, O_RDWR|O_NDELAY)) < 0) {
 			log_fd = -2;
-			/* log to main console instead */
-			device = CONSOLE;
-		} else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
-			log_fd = -2;
-			fprintf(stderr, "Bummer, can't write to log on %s!\n", log);
-			log = NULL;
+			fprintf(stderr, "Bummer, can't write to log on %s!\n", VC_5);
 			device = CONSOLE;
 		}
 	}
@@ -381,19 +371,12 @@
 		/* Perhaps we should panic here? */
 		safe_strncpy(console, "/dev/null", sizeof(console));
 	} else {
-		/* check for serial console and disable logging to tty5 & 
-		 * running a shell to tty2-4 */
+		/* check for serial console */
 		if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
-			log = NULL;
-			secondConsole = NULL;
-			thirdConsole = NULL;
-			fourthConsole = NULL;
 			/* Force the TERM setting to vt102 for serial console --
-			 * iff TERM is set to linux (the default) */
+			 * if TERM is set to linux (the default) */
 			if (strcmp( termType, "TERM=linux" ) == 0)
 				safe_strncpy(termType, "TERM=vt102", sizeof(termType));
-			message(LOG | CONSOLE,
-					"\rserial console detected.  Disabling virtual terminals.\n");
 		}
 		close(fd);
 	}
@@ -802,9 +785,7 @@
 			/* Seems the s390 console is Wierd(tm). */
 			"\rThe system is halted. You may reboot now.\n"
 #else
-			/* secondConsole is NULL for a serial console */
-			"\rThe system is halted. Press %s or turn off power\n",
-			(secondConsole == NULL)? "Reset" : "CTRL-ALT-DEL"
+			"\rThe system is halted. Press Reset or turn off power\n"
 #endif
 		   );
 	sync();
@@ -865,12 +846,8 @@
 	if (*cons == '\0')
 		cons = console;
 
-	/* If BusyBox detects that a serial console is in use, then entries
-	 * not refering to the console or null devices will _not_ be run.
-	 * The exception to this rule is the null device.
-	 */
-	if (secondConsole == NULL && strcmp(cons, console)
-		&& strcmp(cons, "/dev/null"))
+	/* do not run entries if console device is not available */
+	if (access(cons, R_OK|W_OK))
 		return;
 	if (strcmp(cons, "/dev/null") == 0 && (action & ASKFIRST))
 		return;
@@ -944,17 +921,11 @@
 #endif
 		/* Prepare to restart init when a HUP is received */
 		new_init_action(RESTART, "/sbin/init", console);
-		/* Askfirst shell on tty1 */
+		/* Askfirst shell on tty1-4 */
 		new_init_action(ASKFIRST, LOGIN_SHELL, console);
-		/* Askfirst shell on tty2 */
-		if (secondConsole != NULL)
-			new_init_action(ASKFIRST, LOGIN_SHELL, secondConsole);
-		/* Askfirst shell on tty3 */
-		if (thirdConsole != NULL)
-			new_init_action(ASKFIRST, LOGIN_SHELL, thirdConsole);
-		/* Askfirst shell on tty4 */
-		if (fourthConsole != NULL)
-			new_init_action(ASKFIRST, LOGIN_SHELL, fourthConsole);
+		new_init_action(ASKFIRST, LOGIN_SHELL, VC_2);
+		new_init_action(ASKFIRST, LOGIN_SHELL, VC_3);
+		new_init_action(ASKFIRST, LOGIN_SHELL, VC_4);
 		/* sysinit */
 		new_init_action(SYSINIT, INIT_SCRIPT, console);
 
@@ -1113,12 +1084,9 @@
 	if (argc > 1 && (!strcmp(argv[1], "single") ||
 					 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
 		/* Ask first then start a shell on tty2-4 */
-		if (secondConsole != NULL)
-			new_init_action(ASKFIRST, LOGIN_SHELL, secondConsole);
-		if (thirdConsole != NULL)
-			new_init_action(ASKFIRST, LOGIN_SHELL, thirdConsole);
-		if (fourthConsole != NULL)
-			new_init_action(ASKFIRST, LOGIN_SHELL, fourthConsole);
+		new_init_action(ASKFIRST, LOGIN_SHELL, VC_2);
+		new_init_action(ASKFIRST, LOGIN_SHELL, VC_3);
+		new_init_action(ASKFIRST, LOGIN_SHELL, VC_4);
 		/* Start a shell on tty1 */
 		new_init_action(RESPAWN, LOGIN_SHELL, console);
 	} else {


More information about the busybox mailing list