svn commit: trunk/busybox/shell

vda at busybox.net vda at busybox.net
Sat Apr 12 20:07:54 UTC 2008


Author: vda
Date: 2008-04-12 13:07:53 -0700 (Sat, 12 Apr 2008)
New Revision: 21721

Log:
ash: add FEATURE_SH_NOFORK support



Modified:
   trunk/busybox/shell/Config.in
   trunk/busybox/shell/ash.c


Changeset:
Modified: trunk/busybox/shell/Config.in
===================================================================
--- trunk/busybox/shell/Config.in	2008-04-12 20:07:08 UTC (rev 21720)
+++ trunk/busybox/shell/Config.in	2008-04-12 20:07:53 UTC (rev 21721)
@@ -287,6 +287,23 @@
 #	  that exact location with that exact name, this option will not work at
 #	  all.
 
+config FEATURE_SH_NOFORK
+	bool "Run 'nofork' applets directly"
+	default n
+	depends on (MSH || LASH || HUSH || ASH) && FEATURE_PREFER_APPLETS
+	help
+	  This option causes busybox shells [currently only ash]
+	  to not execute typical fork/exec/wait sequence, but call <applet>_main
+	  directly, if possible. (Sometimes it is not possible: for example,
+	  this is not possible in pipes).
+
+	  This will be done only for some applets (those which are marked
+	  NOFORK in include/applets.h).
+
+	  This may significantly speed up some shell scripts.
+
+	  This feature is relatively new. Use with care.
+
 config CTTYHACK
 	bool "cttyhack"
 	default n

Modified: trunk/busybox/shell/ash.c
===================================================================
--- trunk/busybox/shell/ash.c	2008-04-12 20:07:08 UTC (rev 21720)
+++ trunk/busybox/shell/ash.c	2008-04-12 20:07:53 UTC (rev 21721)
@@ -8747,6 +8747,24 @@
 	/* Execute the command. */
 	switch (cmdentry.cmdtype) {
 	default:
+
+#if ENABLE_FEATURE_SH_NOFORK
+		{
+		/* TODO: don't rerun find_applet_by_name, find_command
+		 * already did it. Make it save applet_no somewhere */
+		int applet_no = find_applet_by_name(argv[0]);
+		if (applet_no >= 0 && APPLET_IS_NOFORK(applet_no)) {
+			struct nofork_save_area nofork_save;
+
+			listsetvar(varlist.list, VEXPORT|VSTACK);
+			save_nofork_data(&nofork_save);
+			/* run <applet>_main(), then restore nofork_save_area */
+			exitstatus = run_nofork_applet_prime(&nofork_save, applet_no, argv) & 0xff;
+			break;
+		}
+		}
+#endif
+
 		/* Fork off a child process if necessary. */
 		if (!(flags & EV_EXIT) || trap[0]) {
 			INT_OFF;




More information about the busybox-cvs mailing list