diff options
| author | Ron Yorston <rmy@pobox.com> | 2024-08-17 11:38:30 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2024-08-17 11:57:45 +0100 |
| commit | b21899038683bd646446d3db9e84f64ea669d2ed (patch) | |
| tree | 086a63f81d5b637efaf87792fc0bf1da77e9662e /debianutils | |
| parent | 027fb22e28fecc588d9e088a8d7d77fb63c7dc7b (diff) | |
| download | busybox-w32-b21899038683bd646446d3db9e84f64ea669d2ed.tar.gz busybox-w32-b21899038683bd646446d3db9e84f64ea669d2ed.tar.bz2 busybox-w32-b21899038683bd646446d3db9e84f64ea669d2ed.zip | |
which,ash: code shrink detection of standalone shell
Commit 6d87be4d7 (which,ash: changes to which/command/type) let
'which' detect when it's run from a standalone shell by having
the shell pass the undocumented '-s' option.
A better solution is to alter argv[0] when 'which' is run from a
standalone shell. This is possible because the code path through
run_noexec_applet_and_exit() and which_main() doesn't actually
use argv[0].
- No special treatment is required in ash when 'which' has no
arguments or the '--help' option.
- tryexec() no longer needs an extra element before the start of
argv. The commit 027fb22e2 can be reverted and the allocation
of argv in evalcommand() simplified.
- 'which' no longer needs to handle the '-s' option.
Saves 96-104 bytes.
Diffstat (limited to 'debianutils')
| -rw-r--r-- | debianutils/which.c | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/debianutils/which.c b/debianutils/which.c index 6815768ab..fd3f53d3e 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
| @@ -32,13 +32,6 @@ | |||
| 32 | 32 | ||
| 33 | #include "libbb.h" | 33 | #include "libbb.h" |
| 34 | 34 | ||
| 35 | #if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_STANDALONE | ||
| 36 | enum { | ||
| 37 | OPT_a = (1 << 0), | ||
| 38 | OPT_s = (1 << 1) | ||
| 39 | }; | ||
| 40 | #endif | ||
| 41 | |||
| 42 | int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 35 | int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 43 | int which_main(int argc UNUSED_PARAM, char **argv) | 36 | int which_main(int argc UNUSED_PARAM, char **argv) |
| 44 | { | 37 | { |
| @@ -47,7 +40,8 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
| 47 | /* This sizeof(): bb_default_root_path is shorter than BB_PATH_ROOT_PATH */ | 40 | /* This sizeof(): bb_default_root_path is shorter than BB_PATH_ROOT_PATH */ |
| 48 | char buf[sizeof(BB_PATH_ROOT_PATH)]; | 41 | char buf[sizeof(BB_PATH_ROOT_PATH)]; |
| 49 | #if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_STANDALONE | 42 | #if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_STANDALONE |
| 50 | int sh_standalone; | 43 | /* 'Which' in argv[0] indicates we were run from a standalone shell */ |
| 44 | int sh_standalone = argv[0][0] == 'W'; | ||
| 51 | #endif | 45 | #endif |
| 52 | 46 | ||
| 53 | env_path = getenv("PATH"); | 47 | env_path = getenv("PATH"); |
| @@ -55,14 +49,7 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
| 55 | /* env_path must be writable, and must not alloc, so... */ | 49 | /* env_path must be writable, and must not alloc, so... */ |
| 56 | env_path = strcpy(buf, bb_default_root_path); | 50 | env_path = strcpy(buf, bb_default_root_path); |
| 57 | 51 | ||
| 58 | #if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_STANDALONE | ||
| 59 | /* '-s' option indicates we were run from a standalone shell */ | ||
| 60 | getopt32(argv, "^" "as" "\0" "-1"/*at least one arg*/); | ||
| 61 | sh_standalone = option_mask32 & OPT_s; | ||
| 62 | option_mask32 &= ~OPT_s; | ||
| 63 | #else | ||
| 64 | getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/); | 52 | getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/); |
| 65 | #endif | ||
| 66 | argv += optind; | 53 | argv += optind; |
| 67 | 54 | ||
| 68 | do { | 55 | do { |
