diff options
author | Ron Yorston <rmy@pobox.com> | 2022-05-06 08:26:55 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-05-06 09:30:43 +0100 |
commit | 26ba73098e714459e3294679228a1d54eed14799 (patch) | |
tree | 5e5dda2adbf6577276baf372626465213fd2f1b9 /debianutils | |
parent | 3b5042430fc4b82d44e0430f9ecc21a9228d1651 (diff) | |
download | busybox-w32-26ba73098e714459e3294679228a1d54eed14799.tar.gz busybox-w32-26ba73098e714459e3294679228a1d54eed14799.tar.bz2 busybox-w32-26ba73098e714459e3294679228a1d54eed14799.zip |
win32: search PATH for missing Unix-style executables
Commit 41ef232fc5 (win32: use built-in applets for non-existent
binaries with Unix-style paths) alters what happens when trying
to find an executable. If all of the following apply:
- the pathname starts with one of the standard directories for Unix
executables (/bin, /usr/bin, /sbin, /usr/sbin);
- the file isn't found relative to the system root;
- the basename matches an applet
then the applet is run.
Further extend the procedure so that if the first two conditions are
met and either:
- the PREFER_APPLETS and SH_STANDALONE features are enabled and the
basename *doesn't* match an applet
or
- the PREFER_APPLETS and SH_STANDALONE features are disabled
then PATH is searched for the basename.
This affects:
- how interpreters and binaries are spawned by mingw_spawn_interpreter()
and mingw_spawnvp();
- how 'which' and the shell search for binaries.
Special steps need to be taken in the shell to avoid treating shell
built-ins and functions as applets.
As a consequence of this change:
- An executable that isn't an applet, say curl.exe, can be run as
/usr/bin/curl so long as it's in a directory in PATH. It doesn't
have to be in C:/usr/bin.
- If the PREFER_APPLETS and SH_STANDALONE features are disabled binaries
can be run using paths referring to standard Unix directories even if
they're installed elsewhere in PATH.
Diffstat (limited to 'debianutils')
-rw-r--r-- | debianutils/which.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/debianutils/which.c b/debianutils/which.c index d00b92e0b..4590653b3 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
@@ -93,22 +93,29 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
93 | missing = 0; | 93 | missing = 0; |
94 | puts(bs_to_slash(path)); | 94 | puts(bs_to_slash(path)); |
95 | } | 95 | } |
96 | # if ENABLE_FEATURE_SH_STANDALONE | 96 | else if (unix_path(*argv)) { |
97 | else if (sh_standalone && unix_path(*argv)) { | ||
98 | const char *name = bb_basename(*argv); | 97 | const char *name = bb_basename(*argv); |
99 | 98 | # if ENABLE_FEATURE_SH_STANDALONE | |
100 | if (find_applet_by_name(name) >= 0) { | 99 | if (sh_standalone && find_applet_by_name(name) >= 0) { |
101 | missing = 0; | 100 | missing = 0; |
102 | puts(name); | 101 | puts(name); |
102 | } else | ||
103 | # endif | ||
104 | { | ||
105 | argv[0] = (char *)name; | ||
106 | free(path); | ||
107 | goto try_PATH; | ||
103 | } | 108 | } |
104 | } | 109 | } |
105 | # endif | ||
106 | free(path); | 110 | free(path); |
107 | #endif | 111 | #endif |
108 | } else { | 112 | } else { |
109 | char *path; | 113 | char *path; |
110 | char *p; | 114 | char *p; |
111 | 115 | ||
116 | #if ENABLE_PLATFORM_MINGW32 | ||
117 | try_PATH: | ||
118 | #endif | ||
112 | path = env_path; | 119 | path = env_path; |
113 | /* NOFORK NB: xmalloc inside find_executable(), must have no allocs above! */ | 120 | /* NOFORK NB: xmalloc inside find_executable(), must have no allocs above! */ |
114 | while ((p = find_executable(*argv, &path)) != NULL) { | 121 | while ((p = find_executable(*argv, &path)) != NULL) { |