diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-05-30 22:28:32 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-05-30 22:28:32 +0000 |
commit | 447bd6683729eb6d0f09e30eb68add6297881d01 (patch) | |
tree | 778c20dc4b7f7f176ea43934d8fca9ac3056f5cc | |
parent | f9a07841441e63a96d1a416f68ee2eeb78bface0 (diff) | |
download | busybox-w32-447bd6683729eb6d0f09e30eb68add6297881d01.tar.gz busybox-w32-447bd6683729eb6d0f09e30eb68add6297881d01.tar.bz2 busybox-w32-447bd6683729eb6d0f09e30eb68add6297881d01.zip |
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)
-rw-r--r-- | shell/msh.c | 19 | ||||
-rw-r--r-- | shell/msh_test/msh-execution/exitcode_EACCES.right | 2 | ||||
-rwxr-xr-x | shell/msh_test/msh-execution/exitcode_EACCES.tests | 2 | ||||
-rw-r--r-- | shell/msh_test/msh-execution/exitcode_ENOENT.right | 2 | ||||
-rwxr-xr-x | shell/msh_test/msh-execution/exitcode_ENOENT.tests | 2 |
5 files changed, 21 insertions, 6 deletions
diff --git a/shell/msh.c b/shell/msh.c index 9e06a3bff..840c8bb93 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -594,7 +594,7 @@ static struct op *dowholefile(int /*, int*/); | |||
594 | /* Globals */ | 594 | /* Globals */ |
595 | static char **dolv; | 595 | static char **dolv; |
596 | static int dolc; | 596 | static int dolc; |
597 | static int exstat; | 597 | static uint8_t exstat; |
598 | static smallint gflg; /* (seems to be a parse error indicator) */ | 598 | static smallint gflg; /* (seems to be a parse error indicator) */ |
599 | static smallint interactive; /* Is this an interactive shell */ | 599 | static smallint interactive; /* Is this an interactive shell */ |
600 | static smallint execflg; | 600 | static smallint execflg; |
@@ -806,7 +806,8 @@ static void warn(const char *s) | |||
806 | { | 806 | { |
807 | if (*s) { | 807 | if (*s) { |
808 | prs(s); | 808 | prs(s); |
809 | exstat = -1; | 809 | if (!exstat) |
810 | exstat = 255; | ||
810 | } | 811 | } |
811 | prs("\n"); | 812 | prs("\n"); |
812 | if (FLAG['e']) | 813 | if (FLAG['e']) |
@@ -3071,8 +3072,6 @@ static const char *rexecve(char *c, char **v, char **envp) | |||
3071 | if (tp != global_env.linep) | 3072 | if (tp != global_env.linep) |
3072 | *tp++ = '/'; | 3073 | *tp++ = '/'; |
3073 | strcpy(tp, c); | 3074 | strcpy(tp, c); |
3074 | //for (i = 0; (*tp++ = c[i++]) != '\0';) | ||
3075 | // continue; | ||
3076 | 3075 | ||
3077 | DBGPRINTF3(("REXECVE: global_env.linep is %s\n", global_env.linep)); | 3076 | DBGPRINTF3(("REXECVE: global_env.linep is %s\n", global_env.linep)); |
3078 | 3077 | ||
@@ -3080,10 +3079,13 @@ static const char *rexecve(char *c, char **v, char **envp) | |||
3080 | 3079 | ||
3081 | switch (errno) { | 3080 | switch (errno) { |
3082 | case ENOEXEC: | 3081 | case ENOEXEC: |
3082 | /* File is executable but file format isnt recognized */ | ||
3083 | /* Run it as a shell script */ | ||
3084 | /* (execve above didnt do it itself, unlike execvp) */ | ||
3083 | *v = global_env.linep; | 3085 | *v = global_env.linep; |
3084 | v--; | 3086 | v--; |
3085 | tp = *v; | 3087 | tp = *v; |
3086 | *v = global_env.linep; | 3088 | *v = (char*)DEFAULT_SHELL; |
3087 | execve(DEFAULT_SHELL, v, envp); | 3089 | execve(DEFAULT_SHELL, v, envp); |
3088 | *v = tp; | 3090 | *v = tp; |
3089 | return "no shell"; | 3091 | return "no shell"; |
@@ -3095,7 +3097,12 @@ static const char *rexecve(char *c, char **v, char **envp) | |||
3095 | return "argument list too long"; | 3097 | return "argument list too long"; |
3096 | } | 3098 | } |
3097 | } | 3099 | } |
3098 | return errno == ENOENT ? "not found" : "cannot execute"; | 3100 | if (errno == ENOENT) { |
3101 | exstat = 127; /* standards require this */ | ||
3102 | return "not found"; | ||
3103 | } | ||
3104 | exstat = 126; /* mimic bash */ | ||
3105 | return "cannot execute"; | ||
3099 | } | 3106 | } |
3100 | 3107 | ||
3101 | /* | 3108 | /* |
diff --git a/shell/msh_test/msh-execution/exitcode_EACCES.right b/shell/msh_test/msh-execution/exitcode_EACCES.right new file mode 100644 index 000000000..b13682cde --- /dev/null +++ b/shell/msh_test/msh-execution/exitcode_EACCES.right | |||
@@ -0,0 +1,2 @@ | |||
1 | ./: cannot execute | ||
2 | 126 | ||
diff --git a/shell/msh_test/msh-execution/exitcode_EACCES.tests b/shell/msh_test/msh-execution/exitcode_EACCES.tests new file mode 100755 index 000000000..26b5c6116 --- /dev/null +++ b/shell/msh_test/msh-execution/exitcode_EACCES.tests | |||
@@ -0,0 +1,2 @@ | |||
1 | ./ | ||
2 | echo $? | ||
diff --git a/shell/msh_test/msh-execution/exitcode_ENOENT.right b/shell/msh_test/msh-execution/exitcode_ENOENT.right new file mode 100644 index 000000000..e2bad05e2 --- /dev/null +++ b/shell/msh_test/msh-execution/exitcode_ENOENT.right | |||
@@ -0,0 +1,2 @@ | |||
1 | ./does_exist_for_sure: not found | ||
2 | 127 | ||
diff --git a/shell/msh_test/msh-execution/exitcode_ENOENT.tests b/shell/msh_test/msh-execution/exitcode_ENOENT.tests new file mode 100755 index 000000000..c8866532b --- /dev/null +++ b/shell/msh_test/msh-execution/exitcode_ENOENT.tests | |||
@@ -0,0 +1,2 @@ | |||
1 | ./does_exist_for_sure | ||
2 | echo $? | ||