svn commit: trunk/busybox/shell: msh_test/msh-execution

vda at busybox.net vda at busybox.net
Fri May 30 22:28:33 UTC 2008


Author: vda
Date: 2008-05-30 15:28:32 -0700 (Fri, 30 May 2008)
New Revision: 22128

Log:
msh: fix the case where the file has exec bit but can't be run directly
     (run "$SHELL $file" instead)
msh: fix exit codes when command is not found or can't be execed
     (with testcases)



Added:
   trunk/busybox/shell/msh_test/msh-execution/exitcode_EACCES.right
   trunk/busybox/shell/msh_test/msh-execution/exitcode_EACCES.tests
   trunk/busybox/shell/msh_test/msh-execution/exitcode_ENOENT.right
   trunk/busybox/shell/msh_test/msh-execution/exitcode_ENOENT.tests

Modified:
   trunk/busybox/shell/msh.c


Changeset:
Modified: trunk/busybox/shell/msh.c
===================================================================
--- trunk/busybox/shell/msh.c	2008-05-30 20:38:08 UTC (rev 22127)
+++ trunk/busybox/shell/msh.c	2008-05-30 22:28:32 UTC (rev 22128)
@@ -594,7 +594,7 @@
 /* Globals */
 static char **dolv;
 static int dolc;
-static int exstat;
+static uint8_t exstat;
 static smallint gflg;                   /* (seems to be a parse error indicator) */
 static smallint interactive;            /* Is this an interactive shell */
 static smallint execflg;
@@ -806,7 +806,8 @@
 {
 	if (*s) {
 		prs(s);
-		exstat = -1;
+		if (!exstat)
+			exstat = 255;
 	}
 	prs("\n");
 	if (FLAG['e'])
@@ -3071,8 +3072,6 @@
 		if (tp != global_env.linep)
 			*tp++ = '/';
 		strcpy(tp, c);
-		//for (i = 0; (*tp++ = c[i++]) != '\0';)
-		//	continue;
 
 		DBGPRINTF3(("REXECVE: global_env.linep is %s\n", global_env.linep));
 
@@ -3080,10 +3079,13 @@
 
 		switch (errno) {
 		case ENOEXEC:
+			/* File is executable but file format isnt recognized */
+			/* Run it as a shell script */
+			/* (execve above didnt do it itself, unlike execvp) */
 			*v = global_env.linep;
 			v--;
 			tp = *v;
-			*v = global_env.linep;
+			*v = (char*)DEFAULT_SHELL;
 			execve(DEFAULT_SHELL, v, envp);
 			*v = tp;
 			return "no shell";
@@ -3095,7 +3097,12 @@
 			return "argument list too long";
 		}
 	}
-	return errno == ENOENT ? "not found" : "cannot execute";
+	if (errno == ENOENT) {
+		exstat = 127; /* standards require this */
+		return "not found";
+	}
+	exstat = 126; /* mimic bash */
+	return "cannot execute";
 }
 
 /*

Added: trunk/busybox/shell/msh_test/msh-execution/exitcode_EACCES.right
===================================================================
--- trunk/busybox/shell/msh_test/msh-execution/exitcode_EACCES.right	                        (rev 0)
+++ trunk/busybox/shell/msh_test/msh-execution/exitcode_EACCES.right	2008-05-30 22:28:32 UTC (rev 22128)
@@ -0,0 +1,2 @@
+./: cannot execute
+126

Added: trunk/busybox/shell/msh_test/msh-execution/exitcode_EACCES.tests
===================================================================
--- trunk/busybox/shell/msh_test/msh-execution/exitcode_EACCES.tests	                        (rev 0)
+++ trunk/busybox/shell/msh_test/msh-execution/exitcode_EACCES.tests	2008-05-30 22:28:32 UTC (rev 22128)
@@ -0,0 +1,2 @@
+./
+echo $?


Property changes on: trunk/busybox/shell/msh_test/msh-execution/exitcode_EACCES.tests
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/busybox/shell/msh_test/msh-execution/exitcode_ENOENT.right
===================================================================
--- trunk/busybox/shell/msh_test/msh-execution/exitcode_ENOENT.right	                        (rev 0)
+++ trunk/busybox/shell/msh_test/msh-execution/exitcode_ENOENT.right	2008-05-30 22:28:32 UTC (rev 22128)
@@ -0,0 +1,2 @@
+./does_exist_for_sure: not found
+127

Added: trunk/busybox/shell/msh_test/msh-execution/exitcode_ENOENT.tests
===================================================================
--- trunk/busybox/shell/msh_test/msh-execution/exitcode_ENOENT.tests	                        (rev 0)
+++ trunk/busybox/shell/msh_test/msh-execution/exitcode_ENOENT.tests	2008-05-30 22:28:32 UTC (rev 22128)
@@ -0,0 +1,2 @@
+./does_exist_for_sure
+echo $?


Property changes on: trunk/busybox/shell/msh_test/msh-execution/exitcode_ENOENT.tests
___________________________________________________________________
Name: svn:executable
   + *




More information about the busybox-cvs mailing list