From f26e5634b161e58f56b072f6e703f262e723a80d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 15 Mar 2021 17:42:25 +0100 Subject: 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 --- libbb/appletlib.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'libbb') 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 && strcmp(argv[1], "--help") == 0 && !is_prefixed_with(applet, "busybox") ) { - /* Special case. POSIX says "test --help" - * should be no different from e.g. "test --foo". */ - if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) + /* Special cases. POSIX says "test --help" + * should be no different from e.g. "test --foo". + */ + if (!(ENABLE_TEST && strcmp(applet_name, "test") == 0) + && !(ENABLE_TRUE && strcmp(applet_name, "true") == 0) + && !(ENABLE_FALSE && strcmp(applet_name, "false") == 0) + && !(ENABLE_ECHO && strcmp(applet_name, "echo") == 0) + ) bb_show_usage(); } #endif @@ -891,15 +896,21 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) if (!argv[2]) goto help; /* convert to " --help" */ - argv[0] = argv[2]; + applet_name = argv[0] = argv[2]; argv[2] = NULL; + if (find_applet_by_name(applet_name) >= 0) { + /* Make "--help foo" exit with 0: */ + xfunc_error_retval = 0; + bb_show_usage(); + } /* else: unknown applet, fall through (causes "applet not found" later) */ } else { /* "busybox arg1 arg2 ..." */ argv++; + /* We support "busybox /a/path/to/applet args..." too. Allows for + * "#!/bin/busybox"-style wrappers + */ + applet_name = bb_get_last_path_component_nostrip(argv[0]); } - /* We support "busybox /a/path/to/applet args..." too. Allows for - * "#!/bin/busybox"-style wrappers */ - applet_name = bb_get_last_path_component_nostrip(argv[0]); run_applet_and_exit(applet_name, argv); } # endif @@ -910,7 +921,7 @@ void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv) /* Special case. POSIX says "test --help" * should be no different from e.g. "test --foo". * Thus for "test", we skip --help check. - * "true" and "false" are also special. + * "true", "false", "echo" are also special. */ if (1 # if defined APPLET_NO_test @@ -921,6 +932,9 @@ void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv) # endif # if defined APPLET_NO_false && applet_no != APPLET_NO_false +# endif +# if defined APPLET_NO_echo + && applet_no != APPLET_NO_echo # endif ) { if (argv[1] && !argv[2] && strcmp(argv[1], "--help") == 0) { -- cgit v1.2.3-55-g6feb From c2bd0b680667c7ec4956552f75d9ff7d040ac941 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 23 Mar 2021 13:50:02 +0100 Subject: timeout,top,watch,ping: parse NN.N fractional duration in locales with other separators Signed-off-by: Denys Vlasenko --- coreutils/printf.c | 1 + coreutils/sleep.c | 4 ---- coreutils/sort.c | 1 + libbb/duration.c | 14 ++++++++++++-- miscutils/dc.c | 1 + networking/brctl.c | 1 + 6 files changed, 16 insertions(+), 6 deletions(-) (limited to 'libbb') diff --git a/coreutils/printf.c b/coreutils/printf.c index a20fc3301..dd94c8ade 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -122,6 +122,7 @@ static void FAST_FUNC conv_strtod(const char *arg, void *result) char *end; /* Well, this one allows leading whitespace... so what? */ /* What I like much less is that "-" accepted too! :( */ +//TODO: needs setlocale(LC_NUMERIC, "C")? *(double*)result = strtod(arg, &end); if (end[0]) { errno = ERANGE; diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 7bfaab920..2658e84df 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -74,10 +74,6 @@ int sleep_main(int argc UNUSED_PARAM, char **argv) sleep(INT_MAX); #if ENABLE_FEATURE_FANCY_SLEEP -# if ENABLE_FLOAT_DURATION - /* undo busybox.c setlocale */ - setlocale(LC_NUMERIC, "C"); -# endif duration = 0; do { duration += parse_duration_str(*argv); diff --git a/coreutils/sort.c b/coreutils/sort.c index b194847d1..6c4e3038c 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -295,6 +295,7 @@ static int compare_keys(const void *xarg, const void *yarg) #if ENABLE_FEATURE_SORT_BIG case FLAG_g: { char *xx, *yy; +//TODO: needs setlocale(LC_NUMERIC, "C")? double dx = strtod(x, &xx); double dy = strtod(y, &yy); /* not numbers < NaN < -infinity < numbers < +infinity) */ diff --git a/libbb/duration.c b/libbb/duration.c index 086da15fb..a6a29ddae 100644 --- a/libbb/duration.c +++ b/libbb/duration.c @@ -37,8 +37,18 @@ duration_t FAST_FUNC parse_duration_str(char *str) if (strchr(str, '.')) { double d; char *pp; - int len = strspn(str, "0123456789."); - char sv = str[len]; + int len; + char sv; + +# if ENABLE_LOCALE_SUPPORT + /* Undo busybox.c: on input, we want to use dot + * as fractional separator in strtod(), + * regardless of current locale + */ + setlocale(LC_NUMERIC, "C"); +# endif + len = strspn(str, "0123456789."); + sv = str[len]; str[len] = '\0'; errno = 0; d = strtod(str, &pp); diff --git a/miscutils/dc.c b/miscutils/dc.c index e94dc39e0..42baa67ad 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c @@ -229,6 +229,7 @@ static void stack_machine(const char *argument) const struct op *o; next: +//TODO: needs setlocale(LC_NUMERIC, "C")? number = strtod(argument, &end); if (end != argument) { argument = end; diff --git a/networking/brctl.c b/networking/brctl.c index e1f3e6445..c83aac6e0 100644 --- a/networking/brctl.c +++ b/networking/brctl.c @@ -89,6 +89,7 @@ static unsigned str_to_jiffies(const char *time_str) { double dd; char *endptr; +//TODO: needs setlocale(LC_NUMERIC, "C")? dd = /*bb_*/strtod(time_str, &endptr); if (endptr == time_str || dd < 0) bb_error_msg_and_die(bb_msg_invalid_arg_to, time_str, "timespec"); -- cgit v1.2.3-55-g6feb From 7323bca1b00d96630f52bc3b4182558d6f8cbc92 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 9 Apr 2021 17:02:00 +0200 Subject: lineedit: fix tab completion with equal sign Fix tab completion for the path when equal sign (=) is used. For example: dd if=/dev/ze Signed-off-by: Natanael Copa Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index b0adcf140..2cae4711a 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1071,7 +1071,7 @@ static NOINLINE int build_match_prefix(char *match_buf) continue; for (--i; i >= 0; i--) { int cur = int_buf[i]; - if (cur == ' ' || cur == '<' || cur == '>' || cur == '|' || cur == '&') { + if (cur == ' ' || cur == '<' || cur == '>' || cur == '|' || cur == '&' || cur == '=') { remove_chunk(int_buf, 0, i + 1); break; } -- cgit v1.2.3-55-g6feb From fe2d8065e3e3c251c054a30e9823977e20b5ab7c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 14 Apr 2021 17:52:18 +0200 Subject: fix gcc-11.0 warnings Signed-off-by: Denys Vlasenko --- include/libbb.h | 2 +- libbb/lineedit.c | 2 +- libbb/xfuncs_printf.c | 2 +- networking/udhcp/signalpipe.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libbb') diff --git a/include/libbb.h b/include/libbb.h index ece03e7d8..37732e14e 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -623,7 +623,7 @@ uoff_t FAST_FUNC get_volume_size_in_bytes(int fd, unsigned override_units, int extend); -void xpipe(int filedes[2]) FAST_FUNC; +void xpipe(int *filedes) FAST_FUNC; /* In this form code with pipes is much more readable */ struct fd_pair { int rd; int wr; }; #define piped_pair(pair) pipe(&((pair).rd)) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 2cae4711a..68d19e127 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1314,7 +1314,7 @@ static NOINLINE void input_tab(smallint *lastWasTab) strcpy(&command[cursor_mb], chosen_match + match_pfx_len); len = load_string(command); /* add match and tail */ - sprintf(&command[cursor_mb], "%s%s", chosen_match + match_pfx_len, match_buf); + stpcpy(stpcpy(&command[cursor_mb], chosen_match + match_pfx_len), match_buf); command_len = load_string(command); /* write out the matched command */ /* paranoia: load_string can return 0 on conv error, diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index f0399ca45..d29acebcd 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -224,7 +224,7 @@ int FAST_FUNC rename_or_warn(const char *oldpath, const char *newpath) return n; } -void FAST_FUNC xpipe(int filedes[2]) +void FAST_FUNC xpipe(int *filedes) { if (pipe(filedes)) bb_simple_perror_msg_and_die("can't create pipe"); diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c index 7df671245..774c4beee 100644 --- a/networking/udhcp/signalpipe.c +++ b/networking/udhcp/signalpipe.c @@ -65,7 +65,7 @@ void FAST_FUNC udhcp_sp_setup(void) /* Quick little function to setup the pfds. * Limited in that you can only pass one extra fd. */ -void FAST_FUNC udhcp_sp_fd_set(struct pollfd pfds[2], int extra_fd) +void FAST_FUNC udhcp_sp_fd_set(struct pollfd *pfds, int extra_fd) { pfds[0].fd = READ_FD; pfds[0].events = POLLIN; -- cgit v1.2.3-55-g6feb