[BusyBox] patch: allow init to set controlling tty

Paul Fox pgf at brightstareng.com
Mon Nov 8 16:29:26 UTC 2004


hi --

busybox init will currently strip a leading '-' from the command
name of programs which it invokes.  shells, for instance, are
sometimes specified this way in order to specify a login shell.

this patch (against 1.00) adds a config option which causes init
to cause any such hyphen-prefixed program to run in its own
session, with a controlling tty (if applicable).  this makes it
possible to write startup scripts which will properly respond to
tty-based signals, aborts, etc.  this behavior is non-traditional
for init, but useful.

(i believe there's a (possible?) rewrite of init in the works --
it would be nice if this feature could be carried through there,
as well.)

thanks!
paul

diff -ur busybox-1.00.orig/init/Config.in busybox-1.00/init/Config.in
--- busybox-1.00.orig/init/Config.in	2004-05-26 06:28:32.000000000 -0400
+++ busybox-1.00/init/Config.in	2004-11-08 11:25:34.000000000 -0500
@@ -35,6 +35,17 @@
 	  core file sizes.  If this option is disabled, processes
 	  will not generate any core files.
 
+config CONFIG_FEATURE_INIT_SCTTY
+	bool "  Support running commands with a controlling-tty?"
+	default y
+	depends on CONFIG_INIT
+	help
+	  If this option is enabled a command starting with hyphen (-)
+	  is run in its own session (setsid(2)) and possibly with a
+	  controlling tty (TIOCSCTTY).  This not the traditional init
+	  behavour, but is often what you want in an embedded system where
+	  the console is only accessed during development or for maintenance.
+
 config CONFIG_FEATURE_EXTRA_QUIET
 	bool "  Should init be _extra_ quiet on boot?"
 	default y
diff -ur busybox-1.00.orig/init/init.c busybox-1.00/init/init.c
--- busybox-1.00.orig/init/init.c	2004-10-08 04:21:54.000000000 -0400
+++ busybox-1.00/init/init.c	2004-11-08 11:25:34.000000000 -0500
@@ -574,6 +574,13 @@
 				cmd[0][0] = '-';
 				strcpy(cmd[0] + 1, s);
 			}
+#ifdef CONFIG_FEATURE_INIT_SCTTY
+			/* Establish this process as session leader and
+			 * (attempt) to make the tty (if any) a controlling tty.
+			 */
+			(void) setsid();
+			(void) ioctl(0, TIOCSCTTY, 0/*don't steal it*/);
+#endif
 		}
 
 #if !defined(__UCLIBC__) || defined(__ARCH_HAS_MMU__)


=---------------------
 paul fox, pgf at brightstareng.com



More information about the busybox mailing list