diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-03-15 17:42:25 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-03-15 17:44:53 +0100 |
commit | f26e5634b161e58f56b072f6e703f262e723a80d (patch) | |
tree | 5b66bfa60c13f8e696dd4209a4c3728acd52c58e | |
parent | f25d254dfd4243698c31a4f3153d4ac72aa9e9bd (diff) | |
download | busybox-w32-f26e5634b161e58f56b072f6e703f262e723a80d.tar.gz busybox-w32-f26e5634b161e58f56b072f6e703f262e723a80d.tar.bz2 busybox-w32-f26e5634b161e58f56b072f6e703f262e723a80d.zip |
echo: special case "echo --help": it should not show help text
While at it, fix "busybox --help echo" and other special applets to still print
the help text.
function old new delta
run_applet_and_exit 732 761 +29
show_usage_if_dash_dash_help 70 78 +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 37/0) Total: 37 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/appletlib.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 67c540abb..2feed64dd 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -263,9 +263,14 @@ void lbb_prepare(const char *applet | |||
263 | && strcmp(argv[1], "--help") == 0 | 263 | && strcmp(argv[1], "--help") == 0 |
264 | && !is_prefixed_with(applet, "busybox") | 264 | && !is_prefixed_with(applet, "busybox") |
265 | ) { | 265 | ) { |
266 | /* Special case. POSIX says "test --help" | 266 | /* Special cases. POSIX says "test --help" |
267 | * should be no different from e.g. "test --foo". */ | 267 | * should be no different from e.g. "test --foo". |
268 | if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) | 268 | */ |
269 | if (!(ENABLE_TEST && strcmp(applet_name, "test") == 0) | ||
270 | && !(ENABLE_TRUE && strcmp(applet_name, "true") == 0) | ||
271 | && !(ENABLE_FALSE && strcmp(applet_name, "false") == 0) | ||
272 | && !(ENABLE_ECHO && strcmp(applet_name, "echo") == 0) | ||
273 | ) | ||
269 | bb_show_usage(); | 274 | bb_show_usage(); |
270 | } | 275 | } |
271 | #endif | 276 | #endif |
@@ -891,15 +896,21 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
891 | if (!argv[2]) | 896 | if (!argv[2]) |
892 | goto help; | 897 | goto help; |
893 | /* convert to "<applet> --help" */ | 898 | /* convert to "<applet> --help" */ |
894 | argv[0] = argv[2]; | 899 | applet_name = argv[0] = argv[2]; |
895 | argv[2] = NULL; | 900 | argv[2] = NULL; |
901 | if (find_applet_by_name(applet_name) >= 0) { | ||
902 | /* Make "--help foo" exit with 0: */ | ||
903 | xfunc_error_retval = 0; | ||
904 | bb_show_usage(); | ||
905 | } /* else: unknown applet, fall through (causes "applet not found" later) */ | ||
896 | } else { | 906 | } else { |
897 | /* "busybox <applet> arg1 arg2 ..." */ | 907 | /* "busybox <applet> arg1 arg2 ..." */ |
898 | argv++; | 908 | argv++; |
909 | /* We support "busybox /a/path/to/applet args..." too. Allows for | ||
910 | * "#!/bin/busybox"-style wrappers | ||
911 | */ | ||
912 | applet_name = bb_get_last_path_component_nostrip(argv[0]); | ||
899 | } | 913 | } |
900 | /* We support "busybox /a/path/to/applet args..." too. Allows for | ||
901 | * "#!/bin/busybox"-style wrappers */ | ||
902 | applet_name = bb_get_last_path_component_nostrip(argv[0]); | ||
903 | run_applet_and_exit(applet_name, argv); | 914 | run_applet_and_exit(applet_name, argv); |
904 | } | 915 | } |
905 | # endif | 916 | # endif |
@@ -910,7 +921,7 @@ void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv) | |||
910 | /* Special case. POSIX says "test --help" | 921 | /* Special case. POSIX says "test --help" |
911 | * should be no different from e.g. "test --foo". | 922 | * should be no different from e.g. "test --foo". |
912 | * Thus for "test", we skip --help check. | 923 | * Thus for "test", we skip --help check. |
913 | * "true" and "false" are also special. | 924 | * "true", "false", "echo" are also special. |
914 | */ | 925 | */ |
915 | if (1 | 926 | if (1 |
916 | # if defined APPLET_NO_test | 927 | # if defined APPLET_NO_test |
@@ -922,6 +933,9 @@ void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv) | |||
922 | # if defined APPLET_NO_false | 933 | # if defined APPLET_NO_false |
923 | && applet_no != APPLET_NO_false | 934 | && applet_no != APPLET_NO_false |
924 | # endif | 935 | # endif |
936 | # if defined APPLET_NO_echo | ||
937 | && applet_no != APPLET_NO_echo | ||
938 | # endif | ||
925 | ) { | 939 | ) { |
926 | if (argv[1] && !argv[2] && strcmp(argv[1], "--help") == 0) { | 940 | if (argv[1] && !argv[2] && strcmp(argv[1], "--help") == 0) { |
927 | /* Make "foo --help" exit with 0: */ | 941 | /* Make "foo --help" exit with 0: */ |