aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
AgeCommit message (Collapse)Author
2020-11-30decrease paddign: gcc-9.3.1 slaps 32-byte alignment on arrays willy-nillyDenys Vlasenko
text data bss dec hex filename 1021988 559 5052 1027599 fae0f busybox_old 1021236 559 5052 1026847 fab1f busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-16hush: make interactive ^C break out of PS2 modeDenys Vlasenko
function old new delta syntax_error_unterm_str - 26 +26 parse_stream 2238 2251 +13 fgetc_interactive 243 249 +6 parse_dollar 824 817 -7 syntax_error_unterm_ch 29 21 -8 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/2 up/down: 45/-15) Total: 30 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31shell: update comments on the status of [[ ]] compatDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31shell: better support of [[ ]] bashismDenys Vlasenko
Still rather rudimentary for ash function old new delta binop 433 589 +156 check_operator 65 101 +36 done_word 736 769 +33 test_main 405 418 +13 parse_stream 2227 2238 +11 ops_texts 124 133 +9 ops_table 80 86 +6 run_pipe 1557 1562 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/0 up/down: 269/0) Total: 269 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24hush: output bash-compat killing signal namesDenys Vlasenko
This significantly syncronises ash-signals and hush-signals tests. function old new delta process_wait_result 449 450 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24hush: do not print killing signal name in `cmd_whihc_dies_on_signal`Denys Vlasenko
function old new delta process_wait_result 438 449 +11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-24nologin: make it possible to build it as single appletDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-24suppress a few compile warningsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-04-30ash,hush: drop pointer check before calls to show_historyRon Yorston
show_history() checks that its argument in non-null so there's no need to repeat the test at call sites. function old new delta historycmd 25 17 -8 builtin_history 29 21 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-16) Total: -16 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21hush: fix negative_arith.tests: glob-protect dash in "$((arith))"Denys Vlasenko
function old new delta expand_vars_to_list 1026 1082 +56 parse_dollar 810 811 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 57/0) Total: 57 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21hush: make "exit" in trap use pre-trap exitcode - fix for nested trapDenys Vlasenko
function old new delta check_and_run_traps 276 278 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21hush: make "exit" in trap use pre-trap exitcodeDenys Vlasenko
function old new delta check_and_run_traps 259 276 +17 builtin_exit 42 53 +11 hush_main 1086 1096 +10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 38/0) Total: 38 bytes Fixes exitcode_trap2.tests. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20hush: implement "return NUM in trap sets $? after trap"Denys Vlasenko
function old new delta builtin_return 47 67 +20 check_and_run_traps 243 259 +16 run_pipe 1583 1597 +14 hush_main 1076 1086 +10 run_list 1054 1055 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 61/0) Total: 61 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-18ash,hush: add comment about masked SIGCHLD, handle SIG_IGNed SIGHUP as in bashDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29ash,hush: allow builtins to be tab-completed, closes 7532Ron Yorston
function old new delta complete_cmd_dir_file 678 830 +152 get_builtin_name - 35 +35 optschanged 125 132 +7 hush_main 1069 1076 +7 save_command_ps_at_cur_history 76 78 +2 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/0 up/down: 203/0) Total: 203 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-28hush: fix preprocessor directives indentationDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-01hush: restore redirected stdinDenys Vlasenko
function old new delta restore_redirects 52 95 +43 save_fd_on_redirect 243 253 +10 hfopen 90 99 +9 fgetc_interactive 259 261 +2 builtin_type 117 115 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 64/-2) Total: 62 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-05hush: fix "set -o INVALID" affecting -e flag stateDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02libbb: reduce the overhead of single parameter bb_error_msg() callsJames Byrne
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-03ash,hush: show 'c' in $- if run in "sh -c CMD"Denys Vlasenko
function old new delta options 552 599 +47 expand_one_var 2375 2385 +10 optletters_optnames 60 64 +4 hush_main 1108 1111 +3 ash_main 1150 1152 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 66/0) Total: 66 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-19hush: show 's' in $-Denys Vlasenko
function old new delta expand_one_var 2362 2375 +13 hush_main 1104 1108 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 17/0) Total: 17 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-19hush: allocate line edit buffer only for interactive shellDenys Vlasenko
function old new delta builtin_history 16 20 +4 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-19hush: implement $-, set default PATH if it is not set on startupDenys Vlasenko
function old new delta expand_one_var 2311 2362 +51 hush_main 1075 1104 +29 parse_dollar 790 791 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 81/0) Total: 81 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-19hush: set default PS1/2 only if we interactiveDenys Vlasenko
"env - hush SCRIPT" invocation (that is, with empty environment) should not show PS1/2 in "set" output. function old new delta hush_main 1070 1075 +5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-19hush: handle LINENO the same way as RANDOM: variable is "ephemeral"Denys Vlasenko
"env - hush" invocation (that is, with empty environment) should not show LINENO in "set" output. function old new delta get_local_var_value 263 294 +31 hush_main 1105 1070 -35 handle_changed_special_names 79 38 -41 run_pipe 1834 1765 -69 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 31/-145) Total: -114 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-16hush: remove code to track PS1/2 values dynamically - it's too much workDenys Vlasenko
Assignments / exports / unsets of variables are far more frequent than prompt printing, and if we show prompt, we are likely to be limited by user typing speed - do not optimize for that scenario. Just re-query $PS1 / $PS2 values when need to show the prompt. function old new delta fgetc_interactive 236 259 +23 set_vars_and_save_old 150 147 -3 pseudo_exec_argv 597 594 -3 hush_main 1110 1105 -5 enter_var_nest_level 38 32 -6 builtin_local 56 50 -6 run_pipe 1857 1834 -23 leave_var_nest_level 127 98 -29 handle_changed_special_names 111 79 -32 cmdedit_update_prompt 57 - -57 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/8 up/down: 23/-164) Total: -141 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-16hush: small speedup in handle_changed_special_names()Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-15hush: fix quoted "${notexist-}" expansion to not disappearDenys Vlasenko
function old new delta expand_one_var 2296 2311 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-14hush: fix "export PS1=xyz" and "local PS1=xyz" messing up promptDenys Vlasenko
function old new delta helper_export_local 215 253 +38 leave_var_nest_level 107 127 +20 run_pipe 1840 1857 +17 handle_changed_special_names 101 105 +4 shell_builtin_read 1399 1398 -1 done_word 767 766 -1 parse_stream 2249 2245 -4 set_local_var 437 430 -7 is_well_formed_var_name 66 - -66 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 4/4 up/down: 79/-79) Total: 0 bytes text data bss dec hex filename 952376 485 7296 960157 ea69d busybox_old 952400 485 7296 960181 ea6b5 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-19httpd: use full size of iobuf[] when piping CGI dataDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-16hush: add bash-compatible EPOCH variablesRon Yorston
Bash 5.0 added the dynamic variable EPOCHSECONDS and EPOCHREALTIME which return the number of seconds since the Unix Epoch as an integer or float. These are useful for logging or tracing. function old new delta get_local_var_value 207 302 +95 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 95/0) Total: 95 bytes text data bss dec hex filename 938702 4203 1888 944793 e6a99 busybox_old 938797 4203 1888 944888 e6af8 busybox_unstripped Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-27hush: fix "wait -n" to wait for a _job_, not a _process_Denys Vlasenko
function old new delta checkjobs 163 183 +20 process_wait_result 449 463 +14 leave_var_nest_level 98 107 +9 enter_var_nest_level 32 38 +6 set_vars_and_save_old 147 150 +3 builtin_local 53 56 +3 builtin_wait 322 323 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 7/0 up/down: 56/0) Total: 56 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-26hush: add "wait -n" bashismDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28config: update size informationDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-27randomconfig fixesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-08inetd: suppress aliasing warningDenys Vlasenko
function old new delta sigprocmask2 - 8 +8 wait_for_child_or_signal 213 218 +5 dowait 424 429 +5 block_CHLD_HUP_ALRM 62 59 -3 sigprocmask_SIG_SETMASK 16 - -16 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 2/1 up/down: 18/-19) Total: -1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-08suppress gcc 8 aliasing warningsDenys Vlasenko
function old new delta sigprocmask_SIG_SETMASK - 16 +16 wait_for_child_or_signal 221 213 -8 dowait 432 424 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-27hush: allow hush to run embedded scriptsRon Yorston
Embedded scripts require a shell to be present in the BusyBox binary. Allow either ash or hush to be used for this purpose. If both are enabled ash takes precedence. The size of the binary is unchanged in the default configuration: both ash and hush are present but support for embedded scripts isn't compiled into hush. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-14hush: correct description for HUSH_TICK config optionRon Yorston
The HUSH_TICK configuration option enables command substitution, not process substitution. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-14hush: tweak comment, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-11hush: add a comment on how globbing (should) workDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash,hush: fold shell_builtin_read() way-too-many params into a struct paramDenys Vlasenko
function old new delta getoptscmd 587 584 -3 readcmd 240 224 -16 shell_builtin_read 1426 1399 -27 builtin_read 210 182 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-74) Total: -74 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05hush: set IFS to default on startupDenys Vlasenko
function old new delta hush_main 1095 1110 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05hush: fix fallout from FILE->HFILE conversionDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-04ash,hush: properly handle ${v//pattern/repl} if pattern starts with /Denys Vlasenko
Closes 2695 function old new delta parse_dollar 762 790 +28 subevalvar 1258 1267 +9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 37/0) Total: 37 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-31hush: speed up ${var:+ARG} for literal ARGsDenys Vlasenko
function old new delta first_special_char_in_vararg - 52 +52 expand_one_var 2248 2296 +48 encode_then_expand_vararg 357 336 -21 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 100/-21) Total: 79 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-28hush: fix another case where empty "for" wasn't setting exitcode to 0Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-28hush: disable debug_indent increment/decrement for HUSH_DEBUG < 2 buildsDenys Vlasenko
function old new delta run_list 1063 1046 -17 parse_stream 2296 2249 -47 run_pipe 1890 1840 -50 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-114) Total: -114 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-28hush: make "set -x" output don't redirectable when fd#2 redirectedDenys Vlasenko
function old new delta x_mode_print_optionally_squoted - 120 +120 x_mode_flush - 68 +68 save_fd_on_redirect 208 243 +35 x_mode_prefix - 27 +27 x_mode_addblock - 23 +23 x_mode_addchr - 17 +17 dump_cmd_in_x_mode 110 85 -25 run_pipe 1919 1890 -29 print_optionally_squoted 145 - -145 ------------------------------------------------------------------------------ (add/remove: 5/1 grow/shrink: 1/2 up/down: 290/-199) Total: 91 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-27hush: make "set -x" output closer to bashDenys Vlasenko
function old new delta print_optionally_squoted - 145 +145 run_pipe 1902 1919 +17 dump_cmd_in_x_mode 142 110 -32 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 162/-32) Total: 130 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>