svn commit: trunk/busybox/shell

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


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

Log:
ash: do not do find_applet() twice in shellexec/tryexec



Modified:
   trunk/busybox/shell/ash.c


Changeset:
Modified: trunk/busybox/shell/ash.c
===================================================================
--- trunk/busybox/shell/ash.c	2008-04-12 13:46:39 UTC (rev 21719)
+++ trunk/busybox/shell/ash.c	2008-04-12 20:07:08 UTC (rev 21720)
@@ -6881,21 +6881,18 @@
 
 
 static void
-tryexec(char *cmd, char **argv, char **envp)
+tryexec(USE_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char **envp)
 {
 	int repeated = 0;
 
 #if ENABLE_FEATURE_SH_STANDALONE
-	if (strchr(cmd, '/') == NULL) {
-		int a = find_applet_by_name(cmd);
-		if (a >= 0) {
-			if (APPLET_IS_NOEXEC(a))
-				run_applet_no_and_exit(a, argv);
-			/* re-exec ourselves with the new arguments */
-			execve(bb_busybox_exec_path, argv, envp);
-			/* If they called chroot or otherwise made the binary no longer
-			 * executable, fall through */
-		}
+	if (applet_no >= 0) {
+		if (APPLET_IS_NOEXEC(applet_no))
+			run_applet_no_and_exit(applet_no, argv);
+		/* re-exec ourselves with the new arguments */
+		execve(bb_busybox_exec_path, argv, envp);
+		/* If they called chroot or otherwise made the binary no longer
+		 * executable, fall through */
 	}
 #endif
 
@@ -6931,7 +6928,6 @@
  * Exec a program.  Never returns.  If you change this routine, you may
  * have to change the find_command routine as well.
  */
-#define environment() listvars(VEXPORT, VUNSET, 0)
 static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN;
 static void
 shellexec(char **argv, const char *path, int idx)
@@ -6940,21 +6936,24 @@
 	int e;
 	char **envp;
 	int exerrno;
+#if ENABLE_FEATURE_SH_STANDALONE
+	int applet_no = -1;
+#endif
 
 	clearredir(1);
-	envp = environment();
-	if (strchr(argv[0], '/')
+	envp = listvars(VEXPORT, VUNSET, 0);
+	if (strchr(argv[0], '/') != NULL
 #if ENABLE_FEATURE_SH_STANDALONE
-	 || find_applet_by_name(argv[0]) >= 0
+	 || (applet_no = find_applet_by_name(argv[0])) >= 0
 #endif
 	) {
-		tryexec(argv[0], argv, envp);
+		tryexec(USE_FEATURE_SH_STANDALONE(applet_no,) argv[0], argv, envp);
 		e = errno;
 	} else {
 		e = ENOENT;
 		while ((cmdname = padvance(&path, argv[0])) != NULL) {
 			if (--idx < 0 && pathopt == NULL) {
-				tryexec(cmdname, argv, envp);
+				tryexec(USE_FEATURE_SH_STANDALONE(-1,) cmdname, argv, envp);
 				if (errno != ENOENT && errno != ENOTDIR)
 					e = errno;
 			}
@@ -11630,11 +11629,10 @@
 				if (bcmd)
 					goto builtin_success;
 				continue;
-			} else if (!(act & DO_NOFUNC)
-			 && prefix(pathopt, "func")) {
-				/* handled below */
-			} else {
-				/* ignore unimplemented options */
+			}
+			if ((act & DO_NOFUNC)
+			 || !prefix(pathopt, "func")
+			) {	/* ignore unimplemented options */
 				continue;
 			}
 		}




More information about the busybox-cvs mailing list