diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-12 20:07:08 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-12 20:07:08 +0000 |
commit | 4a9ca13fe7587314aa55a800c86e20fc21d8f2b1 (patch) | |
tree | 1acc260eef5ff6473b2412a0e15c75b7d8ed4809 | |
parent | 55e06c1edf259283e1c7d02ad90be1a5c49c7404 (diff) | |
download | busybox-w32-4a9ca13fe7587314aa55a800c86e20fc21d8f2b1.tar.gz busybox-w32-4a9ca13fe7587314aa55a800c86e20fc21d8f2b1.tar.bz2 busybox-w32-4a9ca13fe7587314aa55a800c86e20fc21d8f2b1.zip |
ash: do not do find_applet() twice in shellexec/tryexec
-rw-r--r-- | shell/ash.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/shell/ash.c b/shell/ash.c index 360d39b4c..0872e681a 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -6881,21 +6881,18 @@ static int builtinloc = -1; /* index in path of %builtin, or -1 */ | |||
6881 | 6881 | ||
6882 | 6882 | ||
6883 | static void | 6883 | static void |
6884 | tryexec(char *cmd, char **argv, char **envp) | 6884 | tryexec(USE_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char **envp) |
6885 | { | 6885 | { |
6886 | int repeated = 0; | 6886 | int repeated = 0; |
6887 | 6887 | ||
6888 | #if ENABLE_FEATURE_SH_STANDALONE | 6888 | #if ENABLE_FEATURE_SH_STANDALONE |
6889 | if (strchr(cmd, '/') == NULL) { | 6889 | if (applet_no >= 0) { |
6890 | int a = find_applet_by_name(cmd); | 6890 | if (APPLET_IS_NOEXEC(applet_no)) |
6891 | if (a >= 0) { | 6891 | run_applet_no_and_exit(applet_no, argv); |
6892 | if (APPLET_IS_NOEXEC(a)) | 6892 | /* re-exec ourselves with the new arguments */ |
6893 | run_applet_no_and_exit(a, argv); | 6893 | execve(bb_busybox_exec_path, argv, envp); |
6894 | /* re-exec ourselves with the new arguments */ | 6894 | /* If they called chroot or otherwise made the binary no longer |
6895 | execve(bb_busybox_exec_path, argv, envp); | 6895 | * executable, fall through */ |
6896 | /* If they called chroot or otherwise made the binary no longer | ||
6897 | * executable, fall through */ | ||
6898 | } | ||
6899 | } | 6896 | } |
6900 | #endif | 6897 | #endif |
6901 | 6898 | ||
@@ -6931,7 +6928,6 @@ tryexec(char *cmd, char **argv, char **envp) | |||
6931 | * Exec a program. Never returns. If you change this routine, you may | 6928 | * Exec a program. Never returns. If you change this routine, you may |
6932 | * have to change the find_command routine as well. | 6929 | * have to change the find_command routine as well. |
6933 | */ | 6930 | */ |
6934 | #define environment() listvars(VEXPORT, VUNSET, 0) | ||
6935 | static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN; | 6931 | static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN; |
6936 | static void | 6932 | static void |
6937 | shellexec(char **argv, const char *path, int idx) | 6933 | shellexec(char **argv, const char *path, int idx) |
@@ -6940,21 +6936,24 @@ shellexec(char **argv, const char *path, int idx) | |||
6940 | int e; | 6936 | int e; |
6941 | char **envp; | 6937 | char **envp; |
6942 | int exerrno; | 6938 | int exerrno; |
6939 | #if ENABLE_FEATURE_SH_STANDALONE | ||
6940 | int applet_no = -1; | ||
6941 | #endif | ||
6943 | 6942 | ||
6944 | clearredir(1); | 6943 | clearredir(1); |
6945 | envp = environment(); | 6944 | envp = listvars(VEXPORT, VUNSET, 0); |
6946 | if (strchr(argv[0], '/') | 6945 | if (strchr(argv[0], '/') != NULL |
6947 | #if ENABLE_FEATURE_SH_STANDALONE | 6946 | #if ENABLE_FEATURE_SH_STANDALONE |
6948 | || find_applet_by_name(argv[0]) >= 0 | 6947 | || (applet_no = find_applet_by_name(argv[0])) >= 0 |
6949 | #endif | 6948 | #endif |
6950 | ) { | 6949 | ) { |
6951 | tryexec(argv[0], argv, envp); | 6950 | tryexec(USE_FEATURE_SH_STANDALONE(applet_no,) argv[0], argv, envp); |
6952 | e = errno; | 6951 | e = errno; |
6953 | } else { | 6952 | } else { |
6954 | e = ENOENT; | 6953 | e = ENOENT; |
6955 | while ((cmdname = padvance(&path, argv[0])) != NULL) { | 6954 | while ((cmdname = padvance(&path, argv[0])) != NULL) { |
6956 | if (--idx < 0 && pathopt == NULL) { | 6955 | if (--idx < 0 && pathopt == NULL) { |
6957 | tryexec(cmdname, argv, envp); | 6956 | tryexec(USE_FEATURE_SH_STANDALONE(-1,) cmdname, argv, envp); |
6958 | if (errno != ENOENT && errno != ENOTDIR) | 6957 | if (errno != ENOENT && errno != ENOTDIR) |
6959 | e = errno; | 6958 | e = errno; |
6960 | } | 6959 | } |
@@ -11630,11 +11629,10 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
11630 | if (bcmd) | 11629 | if (bcmd) |
11631 | goto builtin_success; | 11630 | goto builtin_success; |
11632 | continue; | 11631 | continue; |
11633 | } else if (!(act & DO_NOFUNC) | 11632 | } |
11634 | && prefix(pathopt, "func")) { | 11633 | if ((act & DO_NOFUNC) |
11635 | /* handled below */ | 11634 | || !prefix(pathopt, "func") |
11636 | } else { | 11635 | ) { /* ignore unimplemented options */ |
11637 | /* ignore unimplemented options */ | ||
11638 | continue; | 11636 | continue; |
11639 | } | 11637 | } |
11640 | } | 11638 | } |