summaryrefslogtreecommitdiff
path: root/shell/hush.c
AgeCommit message (Collapse)Author
2018-03-28hush: add a FIXME commentDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-28ash,hush: fix "saved" redirected fds still visible in childrenDenys Vlasenko
Based on a patch by Mark Marshall <mark.marshall@omicronenergy.com> function old new delta dup_CLOEXEC - 49 +49 fcntl_F_DUPFD 46 - -46 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-06hush: code shrinkDenys Vlasenko
function old new delta run_pipe 1589 1591 +2 pseudo_exec_argv 374 375 +1 builtin_type 114 115 +1 find_function 8 - -8 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 3/0 up/down: 4/-8) Total: -4 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02hush: fix a='a\\'; echo "${a%\\\\}"Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02shell: tweak bkslash_in_varexp.tests, add bkslash_in_varexp1.testsDenys Vlasenko
It turns out bkslash_in_varexp.tests was a bash bug :] ash and hush fail "corrected" bkslash_in_varexp.tests as well, just not as badly as I thought (hush gets half of the cases right). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-13hush: simplify process_command_subs()Denys Vlasenko
Incidentally, this fixes LINENO bug here: echo "1:${LINENO}" echo "2:`echo; echo`" # was counting lines in the `cmd` output as LINENO++ echo "3:${LINENO}" function old new delta parse_and_run_file 53 71 +18 expand_vars_to_list 1187 1164 -23 setup_file_in_str 25 - -25 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 18/-48) Total: -30 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-08hush: probably fixing a bug in last LINENO fixDenys Vlasenko
I don't have an example of mishandled script, but the logic looked wrong: it could sometimes treat newlines as if they are spaces. function old new delta parse_stream 2788 2787 -1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-08hush: LINENO fixDenys Vlasenko
Script triggering the bug: t=0 echo "at line ${LINENO}" while [ ${t} -lt 10 ]; do echo "at line ${LINENO}" # LINENO was 3 instead of 4 here t=$((t+1)) done function old new delta parse_stream 2754 2788 +34 done_word 711 738 +27 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 61/0) Total: 61 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-30hush: protect against self-modifying trap codeDenys Vlasenko
function old new delta check_and_run_traps 211 236 +25 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27hush: add HUSH_BASH_SOURCE_CURDIR config option, to be on par with ashDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27hush: fix dot builtin to not search current directoryDenys Vlasenko
function old new delta builtin_source 182 209 +27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25hush: fix two corner cases in ${v/pattern/repl}. Closes 10686Denys Vlasenko
function old new delta expand_one_var 1592 1618 +26 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25hush: fix handling of $_ (so far it's an ordinary variable, no special meaning)Denys Vlasenko
function old new delta parse_dollar 820 779 -41 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19hush: fix a case where EXIT trap may modify its code mid-flightDenys Vlasenko
function old new delta hush_exit 93 99 +6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19hush: fix build if !BASH_LINENO_VARDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19hush: implement $LINENO bashismDenys Vlasenko
function old new delta run_pipe 1697 1774 +77 unset_local_var_len 258 301 +43 hush_main 1009 1051 +42 set_local_var 516 554 +38 parse_and_run_file 42 75 +33 i_getch 96 116 +20 .rodata 18858 18876 +18 done_command 106 122 +16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/0 up/down: 287/0) Total: 287 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-13hush: fix raw ^C handlisg in single-quoted stringsDenys Vlasenko
function old new delta parse_stream 2719 2754 +35 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-12hush: tweak command -vV printing code, no logic changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-12hush: implement "command -v -V"Denys Vlasenko
function old new delta pseudo_exec_argv 231 374 +143 if_command_vV_print_and_exit - 127 +127 builtin_set 267 273 +6 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 276/0) Total: 276 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11hush: implement "command" builtin (no options are supported yet)Denys Vlasenko
function old new delta pseudo_exec_argv 194 231 +37 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11hush: fix handling of ^C in evalDenys Vlasenko
function old new delta run_list 1044 1259 +215 builtin_eval 45 126 +81 expand_strvec_to_string 91 - -91 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 2/0 up/down: 296/-91) Total: 205 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11hush: fix handling of raw ^C in scripts: "echo ^C"Denys Vlasenko
function old new delta expand_vars_to_list 1133 1187 +54 parse_stream 2690 2719 +29 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11hush: remove dead codeDenys Vlasenko
function old new delta done_word 761 711 -50 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-12-31randomconfig fixesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-22hush: fix comment parsing in `cmd`, closes 10421Denys Vlasenko
function old new delta parse_stream 2692 2690 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-29hush: GETOPT_RESET() _after_ getopts too.Denys Vlasenko
NOEXEC'ed applets which use getopt() need this. function old new delta builtin_getopts 403 413 +10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-29hush: reuse "OPTIND=..." stringDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-29hush: fix "getopts" builtin to not be upset by other builtins calling getopt()Denys Vlasenko
function old new delta builtin_getopts 363 403 +40 unset_local_var_len 185 215 +30 set_local_var 440 466 +26 reset_traps_to_defaults 151 157 +6 pseudo_exec_argv 320 326 +6 install_special_sighandlers 52 58 +6 pick_sighandler 62 65 +3 execvp_or_die 85 88 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/0 up/down: 120/0) Total: 120 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-17hush: trivial code shrink in builtin_getoptsDenys Vlasenko
function old new delta builtin_getopts 368 363 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-15ash,hush: comment and debug tweaks, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11hush: implement "silent" optstrings of ":opts"Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11hush: fix redirect code (was using uninitialized variables)Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11shell: add OPTARG poisoning to getopt_optarg.testsDenys Vlasenko
ash fails this! Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11hush: teach getopts to set/unset OPTARGDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11hush: getopts builtinDenys Vlasenko
function old new delta builtin_getopts - 271 +271 bltins1 372 384 +12 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 283/0) Total: 283 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-10hush: optional times builtinDenys Vlasenko
function old new delta builtin_times - 108 +108 bltins1 360 372 +12 static.times_tbl - 9 +9 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 1/0 up/down: 129/0) Total: 129 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-09hush: implement -d DELIM option for 'read'Denys Vlasenko
The POSIX standard only requires the 'read' builtin to handle '-r': http://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html However, Bash introduced the option '-d <DELIM>' to override IFS for just one invocation, and it is quite useful. We already support this in ash, let's add it to hush, too. function old new delta builtin_read 263 284 +21 .rodata 163587 163589 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 23/0) Total: 23 bytes Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-07noexec: consolidate codeDenys Vlasenko
function old new delta run_noexec_applet_and_exit - 61 +61 find_applet_by_name 128 124 -4 run_applet_no_and_exit 441 434 -7 tryexec 169 152 -17 pseudo_exec_argv 338 321 -17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/6 up/down: 61/-48) Total: 13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-07noexec: do GETOPT_RESET() before entering APPLET_main()Denys Vlasenko
hush -c 'yes | head -1' was not happy. function old new delta tryexec 159 169 +10 pseudo_exec_argv 328 338 +10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-07noexec: set comm field for noexecsDenys Vlasenko
function old new delta set_task_comm - 18 +18 tryexec 152 159 +7 pseudo_exec_argv 321 328 +7 main 106 97 -9 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/2 up/down: 34/-13) Total: 23 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-07free,stat: make NOEXECDenys Vlasenko
pkill/pgrep/pidof uncovered another quirk: what about noexec's _process names_? Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04sheel: improve comments on signal handlingDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-02hush: do not accept "if() { echo; }" function defDenys Vlasenko
function old new delta parse_stream 2634 2692 +58 msg_and_die_if_script - 21 +21 syntax_error_unexpected_ch 41 46 +5 syntax_error_at 14 18 +4 die_if_script 31 28 -3 setup_redirects 319 308 -11 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/2 up/down: 88/-14) Total: 74 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-02line editing: make read_line_input() not take timeout paramDenys Vlasenko
It's almost always -1. function old new delta read_line_input 3902 3912 +10 new_line_input_t 24 31 +7 pgetc 583 585 +2 save_command_ps_at_cur_history 80 78 -2 read_line 76 74 -2 fgetc_interactive 246 244 -2 addLines 84 82 -2 doCommands 2226 2222 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/5 up/down: 19/-12) Total: 7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-02hush: make SIGINT handling visually less confusingDenys Vlasenko
$ echo $$ 18448 $ echo $? <wait here, run "kill -INT 18448" in other shell><press enter> <=== NOTHING?? $ That empty line does not look right. After this patch: $ echo $$ 18448 $ echo $? <wait here, run "kill -INT 18448" in other shell><press enter> ^C $ function old new delta fgetc_interactive 245 246 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-02NOFORK fixesDenys Vlasenko
"rm -i FILE" and "yes" can now be interrupted by ^C in hush. This also now works: $ usleep 19999999 ^C $ echo $? 130 function old new delta run_pipe 1668 1711 +43 pseudo_exec_argv 312 321 +9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 52/0) Total: 52 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31hush: remove redundant "G_flag_return_in_progress = -1"Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31hush: fix "true | func_with_return" not allowing return.Denys Vlasenko
function old new delta pseudo_exec_argv 305 312 +7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31hush: functions have priority over builtins (!)Denys Vlasenko
function old new delta pseudo_exec_argv 291 305 +14 run_pipe 1560 1555 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-5) Total: 9 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31hush: if STANDALONE, close interactive fd for NOEXECed childrenDenys Vlasenko
function old new delta pseudo_exec_argv 291 305 +14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>