Commit Graph

2454 Commits

Author SHA1 Message Date
Ron Yorston
cad3fc743a libbb: introduce and use fputs_stdout
function                                             old     new   delta
fputs_stdout                                           -      12     +12
zxc_vm_process                                      7237    7230      -7
yes_main                                              85      78      -7
write_block                                          380     373      -7
wrapf                                                305     298      -7
strings_main                                         437     430      -7
show_bridge                                          353     346      -7
rev_main                                             384     377      -7
put_prompt_custom                                     58      51      -7
put_cur_glyph_and_inc_cursor                         168     161      -7
print_numbered_lines                                 152     145      -7
print_named_ascii                                    130     123      -7
print_name                                           135     128      -7
print_login_issue                                    386     379      -7
print_ascii                                          208     201      -7
powertop_main                                       1249    1242      -7
od_main                                             1789    1782      -7
logread_main                                         518     511      -7
head_main                                            804     797      -7
display_process_list                                1319    1312      -7
cut_main                                            1002     995      -7
bb_dump_dump                                        1550    1543      -7
bb_ask_noecho                                        393     386      -7
baseNUM_main                                         702     695      -7
expand_main                                          755     745     -10
dumpleases_main                                      497     487     -10
write1                                                12       -     -12
putcsi                                                37      23     -14
print_login_prompt                                    55      41     -14
paste_main                                           525     511     -14
cat_main                                             440     426     -14
print_it                                             245     230     -15
print_addrinfo                                      1188    1171     -17
print_rule                                           770     750     -20
print_linkinfo                                       842     822     -20
httpd_main                                           791     771     -20
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/34 up/down: 12/-341)         Total: -329 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-03 20:52:40 +01:00
Denys Vlasenko
2b7c1aa92c ash: match bash behavior for ${empty_var/*/repl}
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-09 08:46:54 +01:00
Denys Vlasenko
883cdb79a4 ash: fix ${unset_var/pattern/repl}
function                                             old     new   delta
subevalvar                                          1349    1353      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-09 08:27:37 +01:00
Denys Vlasenko
4e039bab37 ash: improve --help
function                                             old     new   delta
packed_usage                                       33504   33499      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-04 03:50:38 +01:00
Denys Vlasenko
3b053051c7 hush: code shrink
function                                             old     new   delta
hush_main                                           1071    1066      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5)               Total: -5 bytes
   text	   data	    bss	    dec	    hex	filename
1020110	    559	   5020	1025689	  fa699	busybox_old
1020037	    559	   5020	1025616	  fa650	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-04 03:05:34 +01:00
Denys Vlasenko
85158b600d ash: code shrink
function                                             old     new   delta
ash_main                                            1218    1202     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-03 12:14:58 +01:00
Denys Vlasenko
3f8ec00b0c ash: make a strdup copy of $HISTFILE for line editing
Otherwise if $HISTFILE is unset or reassigned, bad things can happen.

function                                             old     new   delta
ash_main                                            1210    1218      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-03 10:55:39 +01:00
Denys Vlasenko
3c13da3dab libbb: introduce and use xgettimeofday(), do not truncate 64-bit time_t in shells
function                                             old     new   delta
xgettimeofday                                          -      11     +11
get_local_var_value                                  280     281      +1
svlogd_main                                         1323    1322      -1
change_epoch                                          67      66      -1
timestamp_and_log                                    461     458      -3
hwclock_main                                         301     298      -3
fmt_time_bernstein_25                                135     132      -3
step_time                                            331     326      -5
script_main                                         1207    1202      -5
machtime                                              34      28      -6
curtime                                               61      54      -7
ts_main                                              423     415      -8
nmeter_main                                          761     751     -10
gettime1900d                                          67      46     -21
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/12 up/down: 12/-73)           Total: -61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-30 23:48:01 +01:00
Denys Vlasenko
77a51a2709 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-29 16:53:11 +01:00
Denys Vlasenko
c7ef818768 hush: make comment more clear
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-27 16:04:54 +01:00
Denys Vlasenko
cad20ced86 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25 19:08:16 +01:00
Denys Vlasenko
1237d627e9 hush: fix this case: echo "SCRIPT" | hush
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25 19:01:49 +01:00
Denys Vlasenko
46a71dc30c hush: if !EDITING, do not regenerate prompt for every input char
function                                             old     new   delta
fgetc_interactive                                    261     258      -3
pseudo_exec_argv                                     406     399      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10)             Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25 18:49:29 +01:00
Denys Vlasenko
51a471d05d ash: change "clear ungetc counter on syntax errors" fix to match dash
function                                             old     new   delta
ash_main                                            1203    1210      +7
raise_exception                                       39      26     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-13)              Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-24 00:22:24 +01:00
Denys Vlasenko
521220ed1a hush: fix ^C in INTERACTIVE, !EDITING config
function                                             old     new   delta
refill_HFILE_and_getc                                 88     170     +82
fgetc_interactive                                    226     250     +24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 106/0)             Total: 106 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 23:44:55 +01:00
Denys Vlasenko
18bcaf374c hush: revert "make interactive ^C break out of PS2 mode"
It made ^C break out of the entire shell, if we aren't in PS2 mode.
Need a better idea.

function                                             old     new   delta
expand_one_var                                      2344    2353      +9
syntax_error_unterm_ch                                21      29      +8
parse_dollar                                         817     824      +7
parse_stream                                        2251    2238     -13
fgetc_interactive                                    249     227     -22
syntax_error_unterm_str                               26       -     -26
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 3/2 up/down: 24/-61)            Total: -37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 23:01:18 +01:00
Denys Vlasenko
649acb9e23 hush: fix PS1 prompth in !EDITING config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 15:29:13 +01:00
Denys Vlasenko
a7b52d26c4 hush: fix fallout from tweaking ${var:START:LEN} code
function                                             old     new   delta
expand_one_var                                      2344    2353      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 12:38:03 +01:00
Denys Vlasenko
93e2a22482 shell: for signal exitcode, use 128 | sig, not 128 + sig - MIPS has signal 128
function                                             old     new   delta
wait_for_child_or_signal                             213     214      +1
refill_HFILE_and_getc                                 89      88      -1
getstatus                                             97      96      -1
builtin_wait                                         339     337      -2
checkjobs                                            187     183      -4
process_wait_result                                  450     444      -6
waitcmd                                              290     281      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/6 up/down: 1/-23)             Total: -22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 12:23:21 +01:00
Denys Vlasenko
0ab2dd4f28 hush: fix comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 02:22:08 +01:00
Denys Vlasenko
00eb23b47a bc: do not allocate line editing state until needed
function                                             old     new   delta
xc_read_line                                         324     353     +29
free_line_input_t                                     34      39      +5
xc_vm_init                                           656     640     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 34/-16)             Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 21:36:58 +01:00
Denys Vlasenko
07abc7c6f7 hush: deal with FIXMEs for corner cases in parameter expansion
function                                             old     new   delta
expand_one_var                                      2323    2344     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 10:14:18 +01:00
Denys Vlasenko
bb4e32befa hush: remove one redundant getpid() on every startup
function                                             old     new   delta
hush_main                                           1151    1147      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-20 16:36:00 +01:00
Denys Vlasenko
2124c0ec97 ash: clear ungetc counter on syntax errors
function                                             old     new   delta
raise_exception                                       26      39     +13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-19 14:33:02 +01:00
Denys Vlasenko
91e330a53f shells: a fix for systems without RLIMIT_NICE
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 12:07:54 +01:00
Denys Vlasenko
a8e19608fc hush: code shrink
function                                             old     new   delta
run_applet_main                                        -      20     +20
builtin_kill                                         296     288      -8
builtin_test                                          19      10      -9
builtin_printf                                        19      10      -9
builtin_echo                                          19      10      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 20/-35)            Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-14 03:52:54 +01:00
Denys Vlasenko
63139b531f hush: if login shell, also source ~/.profile
function                                             old     new   delta
hush_main                                           1101    1151     +50

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 22:00:56 +01:00
Denys Vlasenko
49142d48bd hush: NOMMU fix for hush-psubst/tick6.tests
function                                             old     new   delta
hush_main                                           1759    1766      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 18:44:07 +01:00
Denys Vlasenko
9cabd17e55 hush: fix -c SCRIPT handling
function                                             old     new   delta
hush_main                                           1763    1759      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 18:24:11 +01:00
Denys Vlasenko
31df5a3eee ash: reset SIGHUP earlier: allows HUP traps in .profile, closes 13371
function                                             old     new   delta
ash_main                                            1188    1203     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 16:36:28 +01:00
Denys Vlasenko
965b795b87 decrease paddign: gcc-9.3.1 slaps 32-byte alignment on arrays willy-nilly
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-30 13:03:03 +01:00
Cristian Ionescu-Idbohrn
ddfdf68ca1 fix warning: label 'out1' defined but not used
Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-19 13:14:59 +01:00
Denys Vlasenko
4ac35a30db ash: make interactive ^C break out of PS2 mode
Based on patch by Joachim Nilsson <troglobit@gmail.com>

function                                             old     new   delta
pgetc                                                570     547     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-16 13:09:37 +01:00
Denys Vlasenko
dc9c10a7b2 hush: make interactive ^C break out of PS2 mode
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-11-16 13:00:44 +01:00
Denys Vlasenko
64981b4c8e hush: document bugs in [[ =~ ]] comparison
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-01 18:47:24 +01:00
Denys Vlasenko
a7c065354f shell: update comments on the status of [[ ]] compat
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31 04:32:34 +01:00
Denys Vlasenko
b259e97d47 hush: add tests for unquoted < > in [[ ]]
They pass.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31 03:51:37 +01:00
Denys Vlasenko
d2241f5902 shell: better support of [[ ]] bashism
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-31 03:34:07 +01:00
Denys Vlasenko
e16f7eb596 hush: output bash-compat killing signal names
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-24 04:26:43 +02:00
Denys Vlasenko
b65d6cb00f hush: do not print killing signal name in cmd_whihc_dies_on_signal
function                                             old     new   delta
process_wait_result                                  438     449     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24 03:33:32 +02:00
Denys Vlasenko
2496616b0a avoid using strok - eliminates use of hidden global variable
function                                             old     new   delta
udhcp_str2optset                                     616     650     +34
setpriv_main                                         950     975     +25
switch_root_main                                     688     706     +18
parse                                                958     970     +12
getopt_main                                          622     628      +6
parse_resolvconf                                     302     306      +4
mpstat_main                                         1139    1142      +3
static.p                                               4       -      -4
cdcmd                                                717     702     -15
strtok                                               148       -    -148
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 7/1 up/down: 102/-167)          Total: -65 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-06 02:36:47 +02:00
Denys Vlasenko
841878e7ee shell: remove FAST_FUNC from a static function
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 00:57:05 +02:00
Denys Vlasenko
d4dd48f294 shell: add testsuite for "wait $pid" waiting for other tasks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 22:36:36 +02:00
Denys Vlasenko
91e11eba6e ash: jobs: Fix waitcmd busy loop
Upstream commit:

    Date: Tue, 2 Jun 2020 23:46:48 +1000
    jobs: Fix waitcmd busy loop

    We need to clear gotsigchld in waitproc because it is used as
    a loop conditional for the waitcmd case.  Without it waitcmd
    may busy loop after a SIGCHLD.

    This patch also changes gotsigchld into a volatile sig_atomic_t
    to prevent compilers from optimising its accesses away.

    Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

This change also incorporates other changes to bring us closer to upstream.

function                                             old     new   delta
dowait                                               553     636     +83

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 20:35:55 +02:00
Denys Vlasenko
8d5f465a20 ash: jobs: Fix infinite loop in waitproc
Upstream commit:

    Date: Fri, 10 Apr 2020 21:03:09 +1000
    jobs: Fix infinite loop in waitproc

    After we changed the resetting of gotsigchld so that it is only
    done if jp is NULL, we can now get an infinite loop in waitproc
    if gotsigchld is set but there is no outstanding child because
    everything had been waited for previously without gotsigchld being
    zeroed.

    This patch fixes it by always zeroing gotsigchld as we did before.
    The bug that the previous patch was trying to fix is now resolved
    by switching the blocking mode to DOWAIT_NORMAL after the specified
    job has been completed so that we really do wait for all outstanding
    dead children.

    Reported-by: Harald van Dijk <harald@gigawatt.nl>
    Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
dowait                                               553     631     +78

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 20:21:27 +02:00
Denys Vlasenko
777a6357c0 ash: remove a tentative TODO, it's a wrong idea
Upstream tried it, and then reverted by:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Tue, 26 May 2020 23:19:05 +1000
    parser: Fix double-backslash nl in old-style command sub

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 20:21:27 +02:00
Christian Eggers
39925026f6 shell: Fix "read -d ''" behavior
With bash's read builtin it is possible to read from a file (e.g.
device-tree) until the first '\0' character:

IFS= read -r -d '' VARIABLE < file

In busybox ash the -d extension is also implemented, but checking the
read character for '\0' has to be performed after comparing with the
delimiter.

Signed-off-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 18:42:30 +02:00
Denys Vlasenko
67e1529b92 nologin: make it possible to build it as single applet
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-24 15:05:22 +02:00
Denys Vlasenko
d5314e7129 suppress a few compile warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-24 09:31:30 +02:00
Ron Yorston
9f3b410006 ash,hush: drop pointer check before calls to show_history
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-04-30 17:30:02 +02:00
Ron Yorston
da7a6dbfa5 ash: fix build failure when command built-in is disabled
Since commit 7eb8eecbb (ash: eval: Add assignment built-in support
again) building BusyBox with the 'command' built-in disabled fails.

parse_command_args() only needs to be called when the 'command'
built-in is run.  Which it won't be if it's disabled.

v2: Avoiding infinite loops is good, too.  Thanks, Harald van Dijk.

Reported-by: Deweloper <deweloper@wp.pl>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-04-30 16:42:58 +02:00
Denys Vlasenko
9aa751b08a shells: fix exitcode_trapN tests to avoid races
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-26 09:05:52 +01:00
Denys Vlasenko
1555895b4a ash: expand: Fix multiple issues with EXP_DISCARD in evalvar
Upstream commit:

    Date: Wed, 12 Sep 2018 14:27:16 +0800
    expand: Fix multiple issues with EXP_DISCARD in evalvar

    The commit 3cd538634f71538370f5af239f342aec48b7470b broke parameter
    expansion in multiple ways because the EXP_DISCARD flag wasn't set
    or tested for various cases:

            $ src/dash -c 'var=; echo ${var:+nonempty}'
            nonempty
            $ src/dash -u -c 'unset foo bar; echo ${foo+${bar}}'
            dash: 1: bar: parameter not set
            $ src/dash -c 'foo=bar; echo ${foo=BUG}; echo $foo'
            barBUG
            bar
            $

    This patch fixes them by introducing a new discard variable that
    tracks whether the extra word should be discarded or not when it
    is parsed.

    Reported-by: Martijn Dekker <martijn@inlv.org>
    Fixes: 3cd538634f71 ("expand: Do not reprocess data when...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
    Reported-by: Martijn Dekker <martijn@inlv.org>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-24 19:20:51 +01:00
Denys Vlasenko
823318822c ash: expand: Do not reprocess data when expanding words
Upstream patch:

    Date: Wed, 30 May 2018 02:06:03 +0800
    expand: Do not reprocess data when expanding words

    Currently various paths will reprocess data when performing word
    expansion.  For example, expari will skip backwards looking for
    the start of the arithmetic expansion, while evalvar will skip
    unexpanded words manually.

    This is cumbersome and error-prone.  This patch fixes this by
    making word expansions proceed in a linear fashion.  This means
    changing argstr and the various expansion functions such as expari
    and subevalvar to return the next character to be expanded.

    This is inspired by similar code from FreeBSD.  However, we take
    things one step further and completely remove the manual word
    skipping in evalvar.  This is accomplished by introducing a new
    EXP_DISCARD flag that tells argstr to only parse and not produce
    any actual expansions.

    Incidentally, argstr will now always NUL-terminate the expansion
    unless the EXP_WORD flag is set.  This is because all but one
    caller of argstr wants the result to be NUL-termianted.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Also includes two one-line follow-up fixes:

    expand: Eat closing brace for length parameter
            if (subtype == VSLENGTH) {
    +               p++;
                    if (flag & EXP_DISCARD)
    expand: Fix double-decrement in argstr
    -               newloc = expdest - (char *)stackblock() - end;
    +               newloc = q - (char *)stackblock() - end;

and changes in code for bash substring extensions.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-24 19:20:51 +01:00
Ron Yorston
6cda0b04a3 ash: move TRACE statement in evalcommand()
Following recent work on evalcommand() a TRACE statement to report
the status of a forked command was left in the wrong place.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-24 12:52:41 +01:00
Denys Vlasenko
7f19848552 ash: rename some function parameters to match dash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-24 12:48:33 +01:00
Denys Vlasenko
538ee4102b ash: rename stack_nputstr() back to stnputs() to match dash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-24 12:47:19 +01:00
Denys Vlasenko
c2058ec98c ash: Expand here-documents in the current shell environment
Upstream commit:

    Date: Sun, 11 Nov 2007 15:27:00 +0800
    Expand here-documents in the current shell environment

    Previously we always expanded here-documents in a subshell.  This is
    contrary to the POSIX specification and how other shells behave.  What's
    more this slows down many expansions due to the extra fork (however, it
    must be said that it is possible for it speed up certain expansions by
    running it simultaneously with the command on two CPUs).

    This patch move the expansion into the current shell environment.

    Test case:

            unset a
            cat <<- EOF > /dev/null
                    ${a=NOT}
            EOF
            echo ${a}BAD

    Old result:

            BAD

    New result:

            NOTBAD

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-22 20:29:36 +01:00
Denys Vlasenko
c08993f40c ash: parser: Do not push token back before parseheredoc
Upstream commit:

    Date: Mon, 19 Nov 2018 18:43:58 +0800
    parser: Do not push token back before parseheredoc

    When we read the first token in list() we use peektoken instead
    of readtoken as the following code needs to use the same token
    again.  However, this is wrong when we're in a here-document as
    it will clobber the saved token without resetting the tokpushback
    flag.

    This patch fixes it by doing the tokpushback after parseheredoc
    and setting lasttoken again if parseheredoc was called.

    Reported-by: Ron Yorston <rmy@frippery.org>
    Fixes: 7c245aa8ed33 ("[PARSER] Simplify EOF/newline handling in...")
    Fixes: ee5cbe9fd6bc ("[SHELL] Optimize dash -c "command" to avoid a fork")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
    Tested-by: Simon Ser <contact@emersion.fr>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-22 17:26:23 +01:00
Denys Vlasenko
9a1a659707 ash: parser: Fix old-style command substitution here-document crash
Upstream commit:

    Date: Fri, 29 Mar 2019 13:49:59 +0800
    parser: Fix old-style command substitution here-document crash

    ... This is caused by the recent change to
    save/restore here-docment list around command substitutions.  In
    doing so we must finish existing here-documents prior to restoring
    the old here-document list.  This is done for new-style command
    substitutions but not for old-style.

    This patch fixes it by doing it for both.

    Fixes: 51e2d88d6e51 ("parser: Save/restore here-documents in...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-22 16:39:27 +01:00
Denys Vlasenko
e4a0612efd hush: fix negative_arith.tests: glob-protect dash in "$((arith))"
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-21 17:21:34 +01:00
Denys Vlasenko
45dd87aac0 ash: expand: Ensure result is escaped in cvtnum
Upstream commit:

    Date: Fri, 1 Jun 2018 18:25:29 +0800
    expand: Ensure result is escaped in cvtnum

    The minus sign generated from arithmetic expansion is currently
    unquoted which causes anomalies when the result is used in where
    the quoting matters.

    This patch fixes it by explicitly calling memtodest on the result
    in cvtnum.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21 16:30:44 +01:00
Denys Vlasenko
da2e46dff6 ash: memalloc: Avoid looping in growstackto
Upstream commit:

    Date: Thu, 31 May 2018 01:51:48 +0800
    memalloc: Avoid looping in growstackto

    Currently growstackto will repeatedly call growstackblock until
    the requisite size is obtained.  This is wasteful.  This patch
    changes growstackblock to take a minimum size instead.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21 15:25:37 +01:00
Denys Vlasenko
3ced804e31 hush: make "exit" in trap use pre-trap exitcode - fix for nested trap
function                                             old     new   delta
check_and_run_traps                                  276     278      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21 02:55:53 +01:00
Denys Vlasenko
cc9ecd9af1 hush: make "exit" in trap use pre-trap exitcode
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-21 02:18:06 +01:00
Denys Vlasenko
f977e004ce ash: eval: Only restore exit status on exit/return
Upstream commit:

    Date: Fri, 14 Dec 2018 13:52:02 +0800
    eval: Only restore exit status on exit/return

    We unconditionally restore the saved status in exitreset, which
    is incorrect as we only want to do it for exitcmd and returncmd.
    This patch fixes the problem by introducing EXEND.

    Reported-by: Martijn Dekker <martijn@inlv.org>
    Fixes: da30b4b78769 ("[BUILTIN] Exit without arguments in a trap...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20 16:54:29 +01:00
Denys Vlasenko
cd24a50633 ash: Return without arguments in a trap should use status outside traps
Fixes exitcode_trap4.tests.
Upstream commit:

    Date: Mon, 6 Oct 2014 21:51:26 +0800
    Return without arguments in a trap should use status outside traps

    POSIX now requires that return without arguments in a trap should
    return the last command status prior to executing traps.  This
    patch implements this behaviour.

    Incidentally this also changes the behaviour of return without
    arguments in a loop conditional to use the last exit status in
    the body as opposed to the last command in the conditional when
    there is one.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20 16:47:01 +01:00
Denys Vlasenko
bb095f4838 hush: implement "return NUM in trap sets $? after trap"
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-20 16:37:59 +01:00
Ron Yorston
d5bfe26c45 ash: return exit status of nofork applets (again)
Since commit d81af7216 (ash: eval: Reap zombies after built-in commands
and functions) if the shell is compiled with SH_STANDALONE and SH_NOFORK
enabled nofork applets potentially return the incorrect status.

The status value returned by evalcommand() in this case is obtained from
exitstatus in a call to waitforjob(NULL).  This overwrites the status
set for nonfork applets.

If this commit seems familiar it's essentially a reversion of commit
5ccb0e92fa (ash: return exit status of nofork applets).  What was correct
in 2016 is wrong in 2020 and vice versa.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20 10:39:46 +01:00
Denys Vlasenko
ecc85832f8 ash: expand: Merge syntax/quotes in memtodest with flags
Upstream commit:

    Date: Mon, 28 May 2018 00:17:39 +0800
    expand: Merge syntax/quotes in memtodest with flags

    The function arguments syntax and quotes are both derived from
    the expansion flags.  As syntax is only used by memtodest we do
    not need to maintain it outside of the function at all.

    The only place that uses something other than BASESYNTAX or DQSYNTAX
    is exptilde.  However in that case DQSYNTAX has exactly the same
    effect as SQSYNTAX.

    This patch merges these two arguments into a single flags.  The
    macro QUOTES_KEEPNUL has been renamed to EXP_KEEPNUL in order
    to keep the namespace separate.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20 10:37:30 +01:00
Denys Vlasenko
e2dd2afc8e ash: eval: Always set localvar_stop
Upstream commit:

    Date: Thu, 31 May 2018 01:15:34 +0800
    eval: Always set localvar_stop

    The variable localvar_stop is set iff vlocal is true.  gcc doesn't
    get this so we get a spurious warning.

    This patch fixes this by always calling pushlocalvars with vlocal
    and making it only actually do the push if vlocal is non-zero.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20 10:37:30 +01:00
Denys Vlasenko
3e729102a8 ash: eval: Replace with listsetvar with mklocal/setvareq
Upstream commit:

    Date: Sat, 19 May 2018 02:39:55 +0800
    eval: Replace with listsetvar with mklocal/setvareq

    This patch replaces listsetvar with mklocal/setvareq.  As we now
    determine special built-in status prior to variable assignment, we
    no longer have to do a second pass listsetvar.  Instead we will
    call setvareq directly instead of mklocal when necessary.

    In order to do this mklocal can now take a flag in order to mark
    a variable for export.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20 09:36:51 +01:00
Denys Vlasenko
54bef2a8ef ash: eval: Fail immediately with redirections errors for simple command
Upstream commit:

    Date: Sat, 19 May 2018 02:39:54 +0800
    eval: Fail immediately with redirections errors for simple command

    Previously, dash would continue to perform variable expansions
    even if a redirection error occured.  This patch changes it so
    that it fails immediately.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20 09:36:51 +01:00
Denys Vlasenko
7eb8eecbbc ash: eval: Add assignment built-in support again
Upstream commit:

    Date: Sat, 19 May 2018 02:39:52 +0800
    eval: Add assignment built-in support again

    This patch adds assignment built-in support that used to exist
    in dash prior to 0.3.8-15.  This is because it will soon be part
    of POSIX, and the semantics are now much better defined.

    Recognition is done at execution time, so even "command -- export"
    or "var=export; command $var" should work.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20 09:36:51 +01:00
Denys Vlasenko
c91950f315 ash,hush: testcase for "exit" without arguments in a trap
hush fails this one

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-19 12:10:41 +01:00
Denys Vlasenko
23bc562a05 ash,hush: add comment about masked SIGCHLD, handle SIG_IGNed SIGHUP as in bash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-18 16:46:01 +01:00
Denys Vlasenko
47eb979404 ash: jobs: Only clear gotsigchld when waiting for everything
Upstream commit:

    Date: Sat, 19 May 2018 02:39:41 +0800
    jobs: Only clear gotsigchld when waiting for everything

    The gotsigchld flag is always cleared in dowait but not all callers
    of dowait will wait for everything.  In particular, when jp is set
    we only wait until the set job isn't running anymore.

    This patch fixes this by only clearing gotsigchld if jp is unset.
    It also changes the waitcmd to actually set jp which corresponds
    to the behaviour of bash/ksh93/mksh.

    The only other caller of dowait that doesn't wait for everything
    is the jobless reaper.  This is in fact redundant now that we wait
    after every simple command.  This patch removes it.

    Finally as every caller of dowait needs to wait until either the
    given job is not running, or until all terminated jobs have been
    processed, this patch moves the loop into dowait itself.

    Fixes: 03876c0743a5 ("eval: Reap zombies after built-in...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-18 15:37:43 +01:00
Denys Vlasenko
97edfc42f1 ash: jobs - Do not block when waiting on SIGCHLD
Upstream comment:

    Date: Mon, 7 May 2018 00:40:34 +0800
    jobs - Do not block when waiting on SIGCHLD

    Because of the nature of SIGCHLD, the process may have already been
    waited on and therefore we must be prepared for the case that wait
    may block.  So ensure that it doesn't by using WNOHANG.

    Furthermore, multiple jobs may have exited when gotsigchld is set.
    Therefore we need to wait until there are no zombies left.

    Lastly, waitforjob needs to be called with interrupts off and
    the original patch broke that.

    Fixes: 03876c0743a5 ("eval: Reap zombies after built-in...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

While at it, removed INT_ON/OFF in waitforjob() - it must be called
from INT_OFF region anyway.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-18 15:37:22 +01:00
Denys Vlasenko
d81af7216b ash: eval: Reap zombies after built-in commands and functions
Upstream commit:

    Date: Mon, 26 Mar 2018 23:55:50 +0800
    eval: Reap zombies after built-in commands and functions

    Currently dash does not reap dead children after built-in commands
    or functions.  This means that if you construct a loop consisting
    of solely built-in commands and functions, then zombies can hang
    around indefinitely.

    This patch fixes this by reaping when necessary after each built-in
    command and function.

    Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-18 14:28:30 +01:00
Denys Vlasenko
22c75924da ash: exec: Never rehash regular built-ins
Upstream commit:

    Date: Sat, 19 May 2018 02:39:51 +0800
    exec: Never rehash regular built-ins

    As regular (including special) built-ins can never be overridden,
    we should never remove them from the hash table.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17 16:20:05 +01:00
Denys Vlasenko
6c4f87e411 ash: exec: Stricter pathopt parsing
Upstream comment:

    Date: Sat, 19 May 2018 02:39:50 +0800
    exec: Stricter pathopt parsing

    This patch changes the parsing of pathopt.  First of all only
    %builtin and %func (with arbitrary suffixes) will be recognised.
    Any other pathopt will be treated as a normal directory.

    Furthermore, pathopt can now be specified before the directory,
    rather than after it.  In fact, a future version may remove support
    for pathopt suffixes.

    Wherever the pathopt is placed, an optional % may be placed after
    it to terminate the pathopt.

    This is so that it is less likely that a genuine directory containing
    a % sign is parsed as a pathopt.

    Users of padvance outside of exec.c have also been modified:

    1) cd(1) will always treat % characters as part of the path.
    2) chkmail will continue to accept arbitrary pathopt.
    3) find_dot_file will ignore the %builtin pathopt instead of trying
    to do a stat in the accompanying directory (which is usually the
    current directory).

    The patch also removes the clearcmdentry optimisation where we
    attempt to only partially flush the table where possible.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17 16:02:40 +01:00
Denys Vlasenko
b0d2dc7d62 ash: exec: Do not allocate stack string in padvance
Upstream commit:

    Date: Sat, 19 May 2018 02:39:48 +0800
    exec: Do not allocate stack string in padvance

    Many callers of padvance immediately free the allocated string
    so this patch moves the stalloc call to the caller.  Instead of
    returning the allocated string, padvance now returns the length
    to allocate (this may be longer than the actual string length,
    even including the NUL).  For the case where we would previously
    return NULL, we now return -1.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17 15:59:44 +01:00
Denys Vlasenko
c55847fedb ash: memalloc: Add growstackto helper
Upstream commit:

    Date: Sat, 19 May 2018 02:39:46 +0800
    memalloc: Add growstackto helper

    This patch adds the growstackto helper which repeatedly calls
    growstackblock until the requested size is reached.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17 15:59:08 +01:00
Denys Vlasenko
74aaf05170 ash: parser: Save/restore here-documents in command substitution
Upstream comment:

    Date: Sat, 19 May 2018 02:39:42 +0800
    parser: Save/restore here-documents in command substitution

    This patch changes the parsing of here-documents within command
    substitution, both old style and new style.  In particular, the
    original here-document list is saved upon the beginning of parsing
    command substitution and restored when exiting.

    This means that here-documents outside of command substitution
    can no longer be filled by text within it and vice-versa.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17 12:11:26 +01:00
Denys Vlasenko
afc91faedd ash: mkinit: Split reset into exitreset and reset
Upstream commit:

    Date: Sat, 19 May 2018 02:39:40 +0800
    mkinit: Split reset into exitreset and reset

    Previously reset was called after exitshell.  This was changed
    so that it was called before exitshell because certain state needed
    to be reset in order for the EXIT trap to work.

    However, this caused issues because certain other states (such
    as local variables) should not be reset.  This patch fixes this
    by creating a new function exitreset that is called prior to
    exitshell and moving reset back to its original location.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17 11:22:59 +01:00
Denys Vlasenko
9ee5892798 ash: expand: Fix trailing newlines processing in backquote expanding
Upstream commit:

    Date: Mon, 29 Apr 2019 19:13:37 +0500
    expand: Fix trailing newlines processing in backquote expanding

    According to POSIX.1-2008 we should remove newlines only at the end of
    the substitution. Newlines-only substitions causes dash to remove
    newlines before beggining of the substitution. The following code:

        cat <<END
        1
        $(echo "")
        2
        END

    prints "1<newline>2" instead of expected "1<newline><newline>2".

    This patch fixes trailing newlines processing in backquote expanding.

    Signed-off-by: Nikolai Merinov <n.merinov@inango-systems.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17 10:24:32 +01:00
Denys Vlasenko
c2ce888030 ash: parser: Only accept single-digit parameter expansion outside of braces
Upstream commit:

    Date: Mon, 27 May 2019 13:39:37 +0800
    parser: Only accept single-digit parameter expansion outside of braces

    This patch should fix the problem.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17 10:15:35 +01:00
Denys Vlasenko
3f4847b6d9 ash: shell: Fix clang warnings about "string plus integer"
Upstream commit:

    Date: Sat, 15 Dec 2018 18:49:31 +0100
    shell: Fix clang warnings about "string plus integer"

    Building with clang results in some warnings about integer values being
    added to strings.

    While the code itself is fine and the warnings are indeed harmless,
    fixing them also makes the semantic more explicit: what it is actually
    being increased is the address which points to the start of the string
    in order to skip the initial character when some conditions are met.

    Signed-off-by: Antonio Ospite <ao2@ao2.it>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:29:31 +01:00
Denys Vlasenko
e368d851e7 ash: eval: Use the correct expansion mode for fd redirection
Upstream comment:

    Date: Mon, 19 Nov 2018 18:00:32 +0800
    eval: Use the correct expansion mode for fd redirection

    It has been reported that

            echo test >&$EMPTY_VARIABLE

    causes dash to segfault.  This is a symptom of the bigger problem
    that dash tries to perform pathname expansion as well as field
    splitting on the word after >& and <&.  This is wrong and this
    patch fixes it to use the same expansions as done on a normal
    redirection.

    Reported-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:24:33 +01:00
Denys Vlasenko
4ace385809 ash: expand: Fix skipping of command substitution when trimming in evalvar
Upstream commit:

    Date: Mon, 28 May 2018 17:09:48 +0800
    expand: Fix skipping of command substitution when trimming in evalvar

    When we are trimming an unset variable in evalvar, any embedded
    command substitution that should have been skipped are not.  This
    can cause them to be evaluated later should there be other command
    substitutions in the same input word.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:22:32 +01:00
Denys Vlasenko
226b8a143d ash: main: Print \n upon EOF (CTRL-D) when run interactively
Upstream comment:

    Date: Fri, 7 Sep 2018 10:34:14 +0200
    main: Print \n upon EOF (CTRL-D) when run interactively

    Exiting dash via a ^D instead of with "exit" causes dash to forget to
    print a newline.

        sh-3.1$ sh
        sh-3.1$ ^D
        sh-3.1$ dash
        $ sh-3.1$

    It is more neat and tidy to send a newline similarly to what bash does,
    so it doesn't make the next prompt of the parent shell look ugly.

    Suggested by jidanni.

    Signed-off-by: Gerrit Pape <pape@smarden.org>
    Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
    [reworded the patch description]
    Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
    Bug-Debian: http://bugs.debian.org/476422
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:16:52 +01:00
Denys Vlasenko
e880b1fea8 ash: expand: Use HOME in tilde expansion when it is empty
Upstream commit:

    Date: Sun, 27 May 2018 17:31:57 +0800
    expand: Use HOME in tilde expansion when it is empty

    Currently if HOME is set to empty tilde expansion will fail, i.e.,
    it will remain as a literal tilde.  This patch changes it to
    return the empty string as required by POSIX.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:16:35 +01:00
Denys Vlasenko
a7b97e367c ash: builtin: Mark more regular built-ins
Upstream commit:

    Date: Sat, 19 May 2018 02:39:49 +0800
    builtin: Mark more regular built-ins

    This patch marks the following built-ins as regular, meaning that
    they cannot be overriden using PATH search:

            hash
            pwd
            type
            ulimit

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
2bad3a305b ash: jobs: Replace some uses of fmtstr with stpcpy/stpncpy
Upstream commit:

    Date: Sat, 19 May 2018 02:39:45 +0800
    jobs: Replace some uses of fmtstr with stpcpy/stpncpy

    Some uses of fmtstr, particularly the ones without a format string,
    can be replaced with stpcpy or stpncpy.  This patch does that so
    we don't have to introduce unnecessary format strings in order to
    silence compiler warnings.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
3f7fb2c89a ash: output: Fix fmtstr return value
Upstream commit:

    Date: Sat, 19 May 2018 02:39:44 +0800
    output: Fix fmtstr return value

    The function fmtstr is meant to return the actual length of output
    produced, rather than the untruncated length.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
970470e235 ash: main: Only set savestatus in exitcmd
Upstream commit:

    Date: Sat, 19 May 2018 02:39:38 +0800
    main: Only set savestatus in exitcmd

    Currently exitcmd sets exitstatus and then savestatus if the latter
    was previously set.  In fact, as exitcmd always raises an exception
    and will either end up in the setjmp call in main() or exitshell(),
    where exitstatus is always replaced by savestatus if set, we only
    need to set savestatus.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
4ccddc8fb3 ash: [BUILTIN] Exit without arguments in a trap should use status outside traps
Upstream commit:

    Date:   Mon Oct 6 10:39:47 2014 +0800
    [BUILTIN] Exit without arguments in a trap should use status outside traps

    POSIX now requires that exit without arguments in a trap should
    return the last command status prior to executing traps.  This
    patch implements this behaviour.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
f7eea8c235 ash: parser: Fix incorrect eating of backslash newlines
Keeping up with upstream (in our case, 'before patch' code is not buggy).
Upstream commit:

    Date: Fri, 11 May 2018 23:41:25 +0800
    parser: Fix incorrect eating of backslash newlines

    With the introduction of synstack->syntax, a number of references
    to the syntax variable was missed during the conversion.  This
    causes backslash newlines to be incorrectly removed in single
    quote context.

    This patch also combines these calls into a new helper function
    pgetc_top.

    Fixes: ab1cecb40478 ("parser: Add syntax stack for recursive...")
    Reported-by: Leah Neukirchen <leah@vuxu.org>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
acf79f9913 ash: use pgetc_eatbnl() in more places, take 2
Adding previously skipped "readtoken1(pgetc_eatbnl(), DQSYNTAX..." changes
from upstream commit:

    Date:   Thu Mar 8 08:37:11 2018 +0100
    Author: Harald van Dijk <harald@gigawatt.nl>
    parser: use pgetc_eatbnl() in more places

    dash has a pgetc_eatbnl function in parser.c which skips any
    backslash-newline combinations. It's not used everywhere it could be.
    There is also some duplicated backslash-newline handling elsewhere in
    parser.c. Replace most of the calls to pgetc() with calls to
    pgetc_eatbnl() and remove the duplicated backslash-newline handling.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Ron Yorston
9e2a5668fd ash,hush: allow builtins to be tab-completed, closes 7532
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>
2020-01-29 15:23:17 +01:00