aboutsummaryrefslogtreecommitdiff
path: root/shell
AgeCommit message (Collapse)Author
2018-11-06ash: minor fixesRon Yorston
Ensure that login_sh is initialised in procargs even when running an embedded script. The argc argument to ash_main isn't unused when embedded scripts are present. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01ash: fix thinko in last commitDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01ash: in tryexec(), ensure we don't try to run embedded scripts as appletsRon Yorston
Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01ash: recognize embedded scripts in SH_STANDALONE modeRon Yorston
function old new delta find_script_by_name - 51 +51 shellexec 254 271 +17 find_command 990 1007 +17 evalcommand 1653 1661 +8 doCommands 2233 2222 -11 run_applet_and_exit 128 100 -28 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 6/4 up/down: 104/-52) Total: 52 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01claenups for previous commitDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01ash: allow shell scripts to be embedded in the binaryDenys Vlasenko
To assist in the deployment of shell scripts it may be convenient to embed them in the BusyBox binary. 'Embed scripts in the binary' takes any files in the directory 'embed', concatenates them with null separators, compresses them and embeds them in the binary. When scripts are embedded in the binary, scripts can be run as 'busybox SCRIPT [ARGS]' or by usual (sym)link mechanism. embed/nologin is provided as an example. function old new delta packed_scripts - 123 +123 unpack_scripts - 87 +87 ash_main 1103 1171 +68 run_applet_and_exit 78 128 +50 get_script_content - 32 +32 script_names - 10 +10 expmeta 663 659 -4 ------------------------------------------------------------------------------ (add/remove: 4/0 grow/shrink: 2/1 up/down: 370/-4) Total: 366 bytes 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-07ash: expand: Do not quote backslashes in unquoted parameter expansionDenys Vlasenko
Upstream commit: Date: Wed, 28 Mar 2018 18:37:51 +0800 expand: Do not quote backslashes in unquoted parameter expansion Here is a better example: a="/*/\nullx" b="/*/\null"; printf "%s\n" $a $b dash currently prints /*/\nullx /*/\null bash prints /*/\nullx /dev/null You may argue the bash behaviour is inconsistent but it actually makes sense. What happens is that quote removal only applies to the original token as seen by the shell. It is never applied to the result of parameter expansion. Now you may ask why on earth does the second line say "/dev/null" instead of "/dev/\null". Well that's because it is not the quote removal step that removed the backslash, but the pathname expansion. The fact that the /de\v does not become /dev even though it exists is just the result of the optimisation to avoid unnecessarily calling stat(2). I have checked POSIX and I don't see anything that forbids this behaviour. So going back to dash yes I think we should adopt the bash behaviour for pathname expansion and keep the existing case semantics. This patch does exactly that. Note that this patch does not work unless you have already applied https://patchwork.kernel.org/patch/10306507/ because otherwise the optimisation mentioned above does not get detected correctly and we will end up doing quote removal twice. This patch also updates expmeta to handle naked backslashes at the end of the pattern which is now possible. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta expmeta 618 653 +35 memtodest 146 147 +1 Tested to work with both ASH_INTERNAL_GLOB on and off. hush does not handle this correctly. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05hush: adopt ash's quote_in_varexp1.testsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: exec: Return 126 on most errors in shellexecDenys Vlasenko
Upstream commit: Date: Sat, 19 May 2018 02:39:37 +0800 exec: Return 126 on most errors in shellexec Currently when shellexec fails on most errors the shell will exit with exit status 2. This patch changes it to 126 in order to avoid ambiguities with the exit status from a successful exec. The errors that result in 127 has also been expanded to include ENOTDIR, ENAMETOOLONG and ELOOP. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta shellexec 245 254 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: eval: Restore input files in evalcommandDenys Vlasenko
Upstream commit: Date: Tue, 27 Mar 2018 00:39:35 +0800 eval: Restore input files in evalcommand When evalcommand invokes a command that modifies parsefile and then bails out without popping the file, we need to ensure the input file is restored so that the shell can continue to execute. Reported-by: Martijn Dekker <martijn@inlv.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta unwindfiles - 20 +20 evalcommand 1635 1653 +18 getoptscmd 584 595 +11 popallfiles 20 10 -10 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/1 up/down: 49/-10) Total: 39 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: parser: Fix parsing of ${}Denys Vlasenko
Upstream commit: Date: Tue, 3 Apr 2018 00:40:25 +0800 parser: Fix parsing of ${} dash -c 'echo ${}' should print "Bad subtitution" but instead fails with "Syntax error: Missing '}'". This is caused by us reading an extra character beyond the right brace. This patch fixes it so that this construct only fails during expansion rather than during parsing. Fixes: 3df3edd13389 ("[PARSER] Report substition errors at...") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta readtoken1 2907 2916 +9 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-05ash: expand: Fix ghost fields with unquoted $@/$*Denys Vlasenko
Upstream commit: Date: Fri, 23 Mar 2018 18:58:47 +0800 expand: Fix ghost fields with unquoted $@/$* You're right. The proper fix to this is to ensure that nulonly is not set in varvalue for $*. It should only be set for $@ when it's inside double quotes. In fact there is another bug while we're playing with $@/$*. When IFS is set to a non-whitespace character such as :, $* outside quotes won't remove empty fields as it should. This patch fixes both problems. Reported-by: Martijn Dekker <martijn@inlv.org> Suggested-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta argstr 1111 1113 +2 evalvar 571 569 -2 varvalue 579 576 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 2/-5) Total: -3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: var: Set IFS to fixed value at start timeDenys Vlasenko
Upstream commit: Date: Sat, 19 May 2018 02:39:43 +0800 var: Set IFS to fixed value at start time This patch forces the IFS variable to always be set to its default value, regardless of the environment. It also removes the long unused IFS_BROKEN code. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: eval: Variable assignments on functions are no longer persistentDenys Vlasenko
Upstream commit: Date: Wed, 4 Apr 2018 17:54:01 +0800 eval: Variable assignments on functions are no longer persistent Dirk Fieldhouse <fieldhouse@gmx.net> wrote: > In POSIX.1-2017 ("simultaneously IEEE Std 1003.1™-2017 and The Open > Group Technical Standard Base Specifications, Issue 7") > <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09>, > we read under '2.9.1 Simple Commands' > > "Variable assignments shall be performed as follows: > ... > - If the command name is a standard utility implemented as a function > (see XBD Utility), the effect of variable assignments shall be as if the > utility was not implemented as a function. > ... > - If the command name is a function that is not a standard utility > implemented as a function, variable assignments shall affect the current > execution environment during the execution of the function. It is > unspecified: > > * Whether or not the variable assignments persist after the > completion of the function > > * Whether or not the variables gain the export attribute during > the execution of the function > > * Whether or not export attributes gained as a result of the > variable assignments persist after the completion of the function (if > variable assignments persist after the completion of the function)" POSIX used to require the current dash behaviour. However, you're right that this is no longer the case. This patch will remove the persistence of the variable assignment. I have considered the exporting the variables during the function execution but have decided against it because: 1) It makes the code bigger. 2) dash has never done this in the past. 3) You cannot use this portably anyway. Reported-by: Dirk Fieldhouse <fieldhouse@gmx.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta evalcommand 1606 1635 +29 evalcase 313 317 +4 evalfun 280 268 -12 pushlocalvars 48 - -48 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 2/1 up/down: 33/-60) Total: -27 bytes 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>
2018-07-27hush: fix "set -x" output prefix overlapping for v="..`cmd`.." caseDenys Vlasenko
Was printing initial "+" prefix for the assignment, that printing "+ cmd" then printing the expanded " v=VAL" string. Delay printing of "+" prefix for the assignment to after expansion. function old new delta run_pipe 1883 1902 +19 builtin_eval 127 133 +6 expand_vars_to_list 1103 1106 +3 dump_cmd_in_x_mode 144 142 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 28/-2) Total: 26 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-27hush: in some cases, expand_on_ifs() relied of uninitialized memoryDenys Vlasenko
The n > 0 check to prevent access to the last byte of non-existing argv[-1] wasn't enough. Switched to making sure there are initialized (zero) bytes there. A predictable testcase is rather hard to construct, unfortunately, contents of memory depends on allocator behavior and whatnot. function old new delta o_save_ptr_helper 119 137 +18 expand_on_ifs 345 339 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-6) Total: 12 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-26hush: improve set -x: make "+++" indent level increase in `cmd` and eval.Denys Vlasenko
function old new delta dump_cmd_in_x_mode 126 144 +18 run_pipe 1873 1883 +10 builtin_eval 119 127 +8 expand_vars_to_list 1100 1103 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 39/0) Total: 39 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24hush: fix/explain corner cases of redirection colliding with script fdDenys Vlasenko
function old new delta save_fd_on_redirect 200 208 +8 run_pipe 1870 1873 +3 setup_redirects 321 322 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 12/0) Total: 12 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24hush: add "heredoc.tests" from ash, tweak ash "is a function" messageDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24hush: fix nested redirects colliding with script fdsDenys Vlasenko
This necessitates switch from libc FILE api to a simple homegrown replacement. The change which fixes the bug here is the deleting of restore_redirected_FILEs(); line. It was prematurely moving (restoring) script fd#3. The fix is: we don't even _want_ to restore scrit fds, we are perfectly fine with them being moved. The only reason we tried to restore them is that FILE api did not allow moving of FILE->fd. function old new delta refill_HFILE_and_getc - 93 +93 hfopen - 90 +90 hfclose - 66 +66 pseudo_exec_argv 591 597 +6 hush_main 1089 1095 +6 builtin_source 209 214 +5 save_fd_on_redirect 197 200 +3 setup_redirects 320 321 +1 fgetc_interactive 235 236 +1 i_peek_and_eat_bkslash_nl 99 97 -2 expand_vars_to_list 1103 1100 -3 restore_redirects 99 52 -47 fclose_and_forget 57 - -57 remember_FILE 63 - -63 ------------------------------------------------------------------------------ (add/remove: 3/2 grow/shrink: 6/3 up/down: 271/-172) Total: 99 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24hush: handle backslash-newline in heredoc terminatorsDenys Vlasenko
function old new delta fetch_heredocs 479 527 +48 (ash fails this test) Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24hush: fix handling of heredocs not enclosed in groups where they are "declared"Denys Vlasenko
function old new delta fetch_heredocs - 479 +479 parse_and_run_stream 146 148 +2 parse_stream 2787 2296 -491 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 481/-491) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-23hush: fix heredoc handling in the "cmd <<EOF ;<newline>" caseDenys Vlasenko
function old new delta parse_stream 2759 2787 +28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-23hush: fix handling of heredocs starting with empty linesDenys Vlasenko
function old new delta parse_stream 2748 2759 +11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: never glob result of dquoted "${v:+/bin/c*}"Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: tidy up code after previous commitsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: better names for o_free_unsafe() / o_free(), no logic changesDenys Vlasenko
o_free() made o_string NULL-initialized, o_free_unsafe() did not bother reinitializing (expected caller to not need it). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: fix handling of '' in ${var:+ARG}Denys Vlasenko
This wasn't an ash bug in dollar_altvalue9, it was hush bug (and bash!) function old new delta expand_one_var 2236 2254 +18 expand_vars_to_list 1097 1103 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 24/0) Total: 24 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: fix word splitting in ${v:+ARG} - dollar_altvalue1 testDenys Vlasenko
ash might be a bit buggy, need to investigate dollar_altvalue9 test function old new delta expand_one_var 1639 2236 +597 expand_variables 112 128 +16 expand_vars_to_list 1117 1097 -20 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 613/-20) Total: 593 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: expand_vars_to_list() should not assume it starts new wordDenys Vlasenko
function old new delta expand_variables 112 115 +3 expand_vars_to_list 1117 1108 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 3/-9) Total: -6 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: remove pointless "next" var, simplify expand_vars_to_list()Denys Vlasenko
function old new delta o_addstr - 26 +26 expand_vars_to_list 1112 1117 +5 encode_then_expand_vararg 398 382 -16 parse_dollar 779 762 -17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/2 up/down: 31/-33) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: store "ended_in_ifs" flag in o_stringDenys Vlasenko
This simplifies function parameter passing. function old new delta expand_one_var 1643 1639 -4 append_str_maybe_ifs_split 64 52 -12 expand_vars_to_list 1125 1112 -13 expand_on_ifs 361 345 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-45) Total: -45 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: propagate (output,n) parameters into expand_one_var()Denys Vlasenko
This is necessary since expand_one_var() for ${var:+ARG} must create more than one output word, and thus can't simply return a char*. function old new delta expand_one_var 1610 1643 +33 expand_vars_to_list 1139 1125 -14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 33/-14) Total: 19 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20hush: make expand_vars_to_list() a bit more saneDenys Vlasenko
function old new delta append_str_maybe_ifs_split - 64 +64 expand_vars_to_list 1167 1139 -28 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 64/-28) Total: 36 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-18hush: reduce indentation, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-18hush: fix 'x=; echo ${x:-"$@"}' producing 'BUG in varexp2' messageDenys Vlasenko
function old new delta expand_string_to_string 126 128 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-18hush: smaller code to set o_string to ""Denys Vlasenko
function old new delta encode_then_expand_vararg 399 398 -1 parse_stream 2753 2748 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-17whitespace fixesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-17hush: faster/smaller code to check for presense of multiple chars in stringDenys Vlasenko
Go over the string only once. function old new delta encode_then_expand_string 126 105 -21 encode_then_expand_vararg 443 399 -44 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-65) Total: -65 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>