[BusyBox] [patch] Make standalone shell more reliable.

Rob Landley rob at landley.net
Thu Apr 7 06:58:16 UTC 2005


If we exec /proc/self/exe and only fall back to /bin/busybox if /proc isn't
there, then we have a reasonable chance of having the standalone shell work
even if busybox isn't installed in /bin on the system in question.

Still won't work in a chroot environment, but it's an improvement.

--- busybox-old/shell/ash.c	2005-03-11 02:20:11.000000000 -0500
+++ busybox/shell/ash.c	2005-04-07 01:01:54.000000000 -0400
@@ -3722,27 +3722,13 @@
 {
 	int repeated = 0;
 #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
-	int flg_bb = 0;
-	char *name = cmd;
-
-	if(strchr(name, '/') == NULL && find_applet_by_name(name) != NULL) {
-		flg_bb = 1;
-	}
-	if(flg_bb) {
-		char **ap;
-		char **new;
-
-		*argv = name;
-		if(strcmp(name, "busybox")) {
-			for (ap = argv; *ap; ap++);
-			ap = new = xmalloc((ap - argv + 2) * sizeof(char *));
-			*ap++ = cmd = "/bin/busybox";
-			while ((*ap++ = *argv++));
-			argv = new;
-			repeated++;
-		} else {
-			cmd = "/bin/busybox";
-		}
+	if(find_applet_by_name(cmd) != NULL) {
+		/* re-exec ourselves with the new arguments */
+		execve("/proc/self/exe",argv,envp);
+		/* If proc isn't mounted, try hardcoded path to busybox binary*/
+		execve("/bin/busybox",argv,envp);
+		/* If they called chroot or otherwise made the binary no longer
+		 * executable, fall through */
 	}
 #endif
 



More information about the busybox mailing list