Commit Graph

2354 Commits

Author SHA1 Message Date
Denys Vlasenko
49015a60cb hush: fix mishandling of "true | f() { echo QWE; }"
function                                             old     new   delta
run_pipe                                            1820    1826      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-03 13:02:43 +02:00
Denys Vlasenko
5fa0505f8a hush: fix "set -e; false || x=1; echo OK"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-03 11:21:13 +02:00
Denys Vlasenko
11752d46d1 hush: one-word, no-globbing handling of local/export/readonly args
function                                             old     new   delta
done_word                                            738     790     +52

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-03 08:20:58 +02:00
Denys Vlasenko
f50e14632f ash: parser: Fix parameter expansion inside inner double quotes
Upstream email:

    parser: Fix parameter expansion inside inner double quotes

    The parsing of parameter expansion inside inner double quotes
    breaks because we never look for ENDVAR while innerdq is true.

            echo "${x#"${x+''}"''}

    This patch fixes it by pushing the syntax stack if innerdq is
    true and we enter a new parameter expansion.

    This patch also fixes a corner case where a bad substitution error
    occurs within arithmetic expansion.

    Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
    Fixes: ab1cecb40478 (" parser: Add syntax stack for recursive...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
readtoken1                                          2880    2898     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 21:00:59 +02:00
Denys Vlasenko
abf755615e hush: fix a backslash-removal bug in case
function                                             old     new   delta
run_list                                            1270    1053    -217

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 17:25:18 +02:00
Denys Vlasenko
9a95df9046 ash: expand: Fix bugs with words connected to the right of $@
Upstream email:

    This is actually composed of two bugs.  First of all our tracking
    of quotemark is wrong so anything after "$@" becomes quoted.  Once
    we fix that then the problem is that the first space character
    after "$@" is not recognised as an IFS.

    This patch fixes both.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 14:27:50 +02:00
Denys Vlasenko
355ec353be ash: redir: Fix typo in noclobber code
Upstream commit "redir: Fix typo in noclobber code"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:34:57 +02:00
Denys Vlasenko
c4c2012284 ash: parser: Fix single-quoted patterns in here-documents
Upstream commit:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Fri, 9 Mar 2018 23:07:53 +0800
    parser: Fix single-quoted patterns in here-documents

    The script

            x=*
            cat <<- EOF
                    ${x#'*'}
            EOF

    prints * instead of nothing as it should.  The problem is that
    when we're in sqsyntax context in a here-document, we won't add
    CTLESC as we should.  This patch fixes it:

    Reported-by: Harald van Dijk <harald@gigawatt.nl>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:29:20 +02:00
Denys Vlasenko
8b536eb40d hush: remove stray debugging printout
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:26:16 +02:00
Denys Vlasenko
216913c290 ash: parser: Add syntax stack for recursive parsing
This closes 10821.

Upstream patch:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Fri, 9 Mar 2018 00:14:02 +0800
    parser: Add syntax stack for recursive parsing

    Without a stack of syntaxes we cannot correctly these two cases
    together:

            "${a#'$$'}"
            "${a#"${b-'$$'}"}"

    A recursive parser also helps in some other corner cases such
    as nested arithmetic expansion with paratheses.

    This patch adds a syntax stack allocated from the stack using
    alloca.  As a side-effect this allows us to remove the naked
    backslashes for patterns within double-quotes, which means that
    EXP_QPAT also has to go.

    This patch also fixes removes any backslashes that precede right
    braces when they are present within a parameter expansion context,
    and backslashes that precede double quotes within inner double
    quotes inside a parameter expansion in a here-document context.

    The idea of a recursive parser is based on a patch by Harald van
    Dijk.

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

var_bash3, var_bash4 and var_bash6 tests are updated
with the output given by bash-4.3.43

With this patch, the following tests now pass for ash:

    dollar_repl_slash_bash2.tests
    squote_in_varexp2.tests
    squote_in_varexp.tests
    var_bash4.tests

function                                             old     new   delta
readtoken1                                          2615    2874    +259
synstack_push                                          -      54     +54
evalvar                                              574     571      -3
rmescapes                                            330     310     -20
subevalvar                                          1279    1258     -21
argstr                                              1146    1107     -39
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/4 up/down: 313/-83)           Total: 230 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:15:37 +02:00
Denys Vlasenko
e84212f834 hush: update information comment about heredoc discrepancy
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 20:11:23 +02:00
Denys Vlasenko
899ae5337a libbb: new function bb_die_memory_exhausted
function                                             old     new   delta
bb_die_memory_exhausted                                -      10     +10
xstrdup                                               28      23      -5
xsetenv                                               27      22      -5
xrealloc                                              32      27      -5
xputenv                                               22      17      -5
xmalloc                                               30      25      -5
xfdopen_helper                                        40      35      -5
xasprintf                                             44      39      -5
wget_main                                           2387    2382      -5
open_socket                                           54      49      -5
glob_brace                                           419     414      -5
bb_get_chunk_from_file                               146     141      -5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/11 up/down: 10/-55)           Total: -45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 19:59:37 +02:00
Denys Vlasenko
bb6f573ad2 hush: add a comment where we differ from bash wrt heredoc EOF mark handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 18:55:00 +02:00
Denys Vlasenko
41fddb4372 parser: Fix backquote support in here-document EOF mark
Upstream commit:

    Author: Herbert Xu <herbert@gondor.apana.org.au>
    Date:   Thu Mar 15 18:27:30 2018 +0800
    parser: Fix backquote support in here-document EOF mark

    Currently using backquotes in a here-document EOF mark is broken
    because dash tries to do command substitution on it.  This patch
    fixes it by checking whether we're looking for an EOF mark during
    tokenisation.

    Reported-by: Harald van Dijk <harald@gigawatt.nl>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

With added fix for quoted-ness of the EOF mark.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 16:38:32 +02:00
Denys Vlasenko
1e5111b0f8 ash,hush: handle a few more bkslash-newline cases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 03:04:55 +02:00
Denys Vlasenko
32e183e63e shells: fix var_LINENO1.tests false positive, add it to ash tests too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 20:31:13 +02:00
Denys Vlasenko
a94eeb0b42 hush: fix heredoc_bkslash_newline1.tests failure
function                                             old     new   delta
parse_stream                                        2787    2827     +40
builtin_type                                         117     115      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 20:16:31 +02:00
Denys Vlasenko
220be537a0 ash: use pgetc_eatbnl() in more places
Part of 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>

Not adding "readtoken1(pgetc_eatbnl(), DQSYNTAX..." changes, since
readtoken1() handles the "starts with backslash + newline" case itself.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 19:40:56 +02:00
Martijn Dekker
ad4e961352 ash: 'nolog' and 'debug' options cause "$-" to wreak havoc
Upstream commit:

    Date:   Tue Mar 6 17:40:37 2018 +0000
    expand: 'nolog' and 'debug' options cause "$-" to wreak havoc

    Op 29-03-17 om 20:02 schreef Martijn Dekker:
    > Bug: if either the 'nolog' or the 'debug' option is set, trying to
    > expand "$-" silently aborts parsing of an entire argument.
    >
    > $ dash -o nolog -c 'set -fuC; echo "|$- are the options|"; set +o nolog; echo "|$- are the options|"'
    > |
    > |uCf are the options|
    > $ dash -o debug -c 'set -fuC; echo "|$- are the options|"; set +o debug; echo "|$- are the options|"'
    > |
    > |uCf are the options|

    This turned out to be easy to fix. The routine producing the "$-"
    expansion failed to skip options for which there is no option letter,
    but only a long-form name. In dash, 'nolog' and 'debug' are currently
    the only two such options. Patch below.

    - Martijn

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

In bbox ash, pipefail is the option which exhibited this.

Signed-off-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 18:30:27 +02:00
Denys Vlasenko
6ffaa00338 hush: fix a signedness bug
Testcase:

set -- a ""; space=" "; printf "<%s>\n" "$@"$space

Before:
<a >
After:
<a>
<>

It usually does not bite since bbox forces -funsigned-char build.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 00:48:18 +02:00
Denys Vlasenko
73523079a2 ash,hush: new test dollar_repl_slash_bash2.tests
This fails for ash. hush works.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 23:25:24 +02:00
Denys Vlasenko
ac61f44704 ash: fix "char == CTLfoo" comparison signedness bug
It usually does not bite since bbox forces -funsigned-char build.
But for some reason void linux people disabled that.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 23:04:39 +02:00
Denys Vlasenko
60fb98e51d ash: use F_DUPFD_CLOEXEC and O_CLOEXEC
function                                             old     new   delta
setjobctl                                            371     367      -4
setinputfile                                         226     220      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10)             Total: -10 bytes

Based on patch by Mark Marshall <mark.marshall@omicronenergy.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 22:15:14 +02:00
Denys Vlasenko
d1b845706d hush: add a FIXME comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-28 18:42:54 +02:00
Denys Vlasenko
9acd63c92c ash,hush: fix "saved" redirected fds still visible in children
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-28 18:35:07 +02:00
Denys Vlasenko
33f7c8f200 hush: code shrink
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-06 17:21:57 +01:00
Denys Vlasenko
d4802c6243 hush: fix a='a\\'; echo "${a%\\\\}"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02 20:48:36 +01:00
Denys Vlasenko
55f8133a4f shell: tweak bkslash_in_varexp.tests, add bkslash_in_varexp1.tests
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-03-02 18:12:12 +01:00
Denys Vlasenko
744a20d8f9 shell: two new tests, both fail for ash and hush
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02 17:13:22 +01:00
Denys Vlasenko
aa617ac097 hush: simplify process_command_subs()
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-13 15:31:19 +01:00
Denys Vlasenko
8de5b9f88b ash : fix double-quoted "\z" handling
function                                             old     new   delta
readtoken1                                          2602    2608      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-13 14:44:11 +01:00
Denys Vlasenko
f786901c4b hush: probably fixing a bug in last LINENO fix
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-08 19:39:42 +01:00
Denys Vlasenko
5807e18f0c hush: LINENO fix
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-02-08 19:19:04 +01:00
Denys Vlasenko
749575d3c5 hush: protect against self-modifying trap code
function                                             old     new   delta
check_and_run_traps                                  211     236     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-30 04:29:03 +01:00
Denys Vlasenko
6f9442ff30 ash: make it possible to disable "const global ptr" optimization
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-28 20:41:23 +01:00
Denys Vlasenko
f19e3c1c6c shell: handle $((NUM++...) like bash does. Closes 10706
function                                             old     new   delta
evaluate_string                                      680     729     +49

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-28 20:13:33 +01:00
Denys Vlasenko
675d24aeaf ash: add LINENO support
This patch is a backport from dash of the combination of:
    [SHELL] Add preliminary LINENO support
    [VAR] Fix varinit ordering that broke fc
    [SHELL] Improve LINENO support

function                                             old     new   delta
parse_command                                       1604    1677     +73
calcsize                                             156     223     +67
copynode                                             196     258     +62
evalcommand                                         1546    1606     +60
ash_main                                            1046    1103     +57
lookupvar                                             51     106     +55
evalcase                                             269     317     +48
evaltree                                             501     547     +46
evalfor                                              156     200     +44
evalsubshell                                         156     195     +39
raise_error_syntax                                    11      29     +18
varinit_data                                         120     132     +12
evalfun                                              270     280     +10
funcline                                               -       4      +4
cmdtxt                                               569     572      +3
trapcmd                                              306     304      -2
ash_vmsg                                             153     150      -3
startlinno                                             4       -      -4
funcnest                                               4       -      -4
xxreadtoken                                          263     250     -13
readtoken1                                          2645    2602     -43
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 14/4 up/down: 598/-69)          Total: 529 bytes
   text	   data	    bss	    dec	    hex	filename
 932834	    481	   6864	 940179	  e5893	busybox_old
 933375	    481	   6856	 940712	  e5aa8	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27 22:02:05 +01:00
Denys Vlasenko
54c2111781 hush: add HUSH_BASH_SOURCE_CURDIR config option, to be on par with ash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27 20:46:45 +01:00
Denys Vlasenko
f7e0feaf97 hush: fix dot builtin to not search current directory
function                                             old     new   delta
builtin_source                                       182     209     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27 19:05:59 +01:00
Denys Vlasenko
01f7b9e182 ash: introduce a config option to search current directory for sourced files
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-26 15:15:43 +01:00
Denys Vlasenko
043be55691 ash testsuite: add two hush tests from last commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25 14:09:06 +01:00
Denys Vlasenko
cba79a87f8 hush: fix two corner cases in ${v/pattern/repl}. Closes 10686
function                                             old     new   delta
expand_one_var                                      1592    1618     +26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25 14:07:40 +01:00
Denys Vlasenko
0ca3198f93 hush: fix handling of $_ (so far it's an ordinary variable, no special meaning)
function                                             old     new   delta
parse_dollar                                         820     779     -41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25 13:20:50 +01:00
William Pitcock
d8fd88a091 ash: add support for command_not_found_handle hook function (bashism)
This implements support for the command_not_found_handle hook function, which is
useful for allowing package managers to suggest packages which could provide the
command.

Unlike bash, however, we ignore exit codes from the hook function and always return
the correct POSIX error code (EX_NOTFOUND).

function                                             old     new   delta
find_command                                         911     990     +79

Signed-off-by: William Pitcock <nenolod@dereferenced.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-24 18:33:18 +01:00
Denys Vlasenko
46f839c3f7 hush: fix a case where EXIT trap may modify its code mid-flight
function                                             old     new   delta
hush_exit                                             93      99      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19 16:58:44 +01:00
Denys Vlasenko
b8d076b00b hush: fix build if !BASH_LINENO_VAR
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19 16:00:57 +01:00
Denys Vlasenko
6aad1ddcc9 hush: implement $LINENO bashism
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-19 15:52:36 +01:00
Denys Vlasenko
1750d3afc1 ash: a bit of NOFORK code should only be active if FEATURE_SH_STANDALONE=y
function                                             old     new   delta
evalcommand                                         1546    1420    -126

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-15 00:41:04 +01:00
Denys Vlasenko
aea52e7b2d shell: echo ${?:0} was fixed sometime ago, enable it in tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-13 19:28:19 +01:00
Denys Vlasenko
9809a82b59 hush: fix raw ^C handlisg in single-quoted strings
function                                             old     new   delta
parse_stream                                        2719    2754     +35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-13 19:14:27 +01:00
Denys Vlasenko
6606c519ef hush: add command2.tests from ash tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-12 17:58:20 +01:00
Denys Vlasenko
afb73a25ea hush: tweak command -vV printing code, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-12 16:17:59 +01:00
Denys Vlasenko
5700029c65 hush: implement "command -v -V"
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-12 14:41:45 +01:00
Denys Vlasenko
3bb3e1d0a1 hush: implement "command" builtin (no options are supported yet)
function                                             old     new   delta
pseudo_exec_argv                                     194     231     +37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11 18:05:05 +01:00
Denys Vlasenko
1f1911239c hush: fix handling of ^C in eval
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-11 13:17:30 +01:00
Denys Vlasenko
932b9971d0 hush: fix handling of raw ^C in scripts: "echo ^C"
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-11 12:39:48 +01:00
Denys Vlasenko
aaf7a2e24d hush: remove dead code
function                                             old     new   delta
done_word                                            761     711     -50

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11 11:19:00 +01:00
Denys Vlasenko
03c36e0be1 ash: ALWAYS_INLINE grabstackblock()
function                                             old     new   delta
grabstackblock                                         5       -      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-10 15:18:35 +01:00
Denys Vlasenko
baa41c7855 ash: make ${v:N:M} more robust for very large M by clamping to MIN/MAX_INT
Before this patch, "${v:2:0x100000001}" = "${v:2:1}",
and similarly, constructs like "${v:2:9999999999}" may give wrong result
due to int overflows.

function                                             old     new   delta
substr_atoi                                            -      43     +43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-10 13:22:25 +01:00
Denys Vlasenko
d1df1a709f ash: add comment explaining last change
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-09 17:25:58 +01:00
Denys Vlasenko
740058b42b ash: fix var_bash5.tests - ${VAR/pattern/repl} construct
function                                             old     new   delta
subevalvar                                          1198    1279     +81
rmescapes                                            308     330     +22
preglob                                                8      10      +2
parsefname                                           152     154      +2
expandarg                                            973     975      +2
argstr                                              1144    1146      +2
mklocal                                              290     288      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/1 up/down: 111/-2)            Total: 109 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-09 17:07:06 +01:00
Ingo van Lil
9c8e94bc0a ash: fail if 'shift' operand is out of range
If the numeric argument passed to ash's 'shift' built-in is greater than
'$#' the command performs no operation and exits successfully. It should
return a non-zero exit code instead:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#shift

This is consistent with bash and hush.

function                                             old     new   delta
shiftcmd                                             122     120      -2

Signed-off-by: Ingo van Lil <inguin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-07 14:22:38 +01:00
Denys Vlasenko
82d1c1f84a randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-12-31 17:30:02 +01:00
Denys Vlasenko
a5060b8364 ash: fix nofork bug where environment is not properly passed to a command
function                                             old     new   delta
listvars                                             144     252    +108
evalcommand                                         1500    1546     +46
showvars                                             142     147      +5
shellexec                                            242     245      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 162/0)             Total: 162 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-11-03 14:16:25 +01:00
Denys Vlasenko
9c143ce52d ash: retain envvars with bad names in initial environment. Closes 10231
Reworks "ash: [VAR] Sanitise environment variable names on entry"
commit.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-11-02 12:56:24 +01:00
Denys Vlasenko
25f3b737dc hush: fix comment parsing in cmd, closes 10421
function                                             old     new   delta
parse_stream                                        2692    2690      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-22 15:55:48 +02:00
Denys Vlasenko
14c85eb7db whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-12 19:40:47 +02:00
Denys Vlasenko
3c183a8758 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-12 19:35:42 +02:00
Denys Vlasenko
a2e32b324e ash: survive failures in $PS1 expansion. Closes 10371
function                                             old     new   delta
expandstr                                            120     209     +89

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-12 19:20:13 +02:00
Denys Vlasenko
6f97b30a90 use %m printf specifier where appropriate
function                                             old     new   delta
out                                                   85      75     -10
udhcpd_main                                         1472    1461     -11
open_stdio_to_tty                                     98      85     -13
init_exec                                            245     232     -13
udhcpc_main                                         2763    2749     -14
do_cmd                                              4771    4755     -16
status_line_bold_errno                                32      14     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-95)             Total: -95 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-29 18:17:25 +02:00
Denys Vlasenko
0c4dbd481a regularize format of source file headers, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-18 16:28:43 +02:00
Denys Vlasenko
9fed83a7cc hush: fix false positive in unset.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-29 14:35:58 +02:00
Denys Vlasenko
6016181b68 hush: GETOPT_RESET() _after_ getopts too.
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-29 14:32:17 +02:00
Denys Vlasenko
55af51c66d hush: reuse "OPTIND=..." string
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-29 13:48:49 +02:00
Denys Vlasenko
238ff98bb8 hush: fix "getopts" builtin to not be upset by other builtins calling getopt()
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-29 13:38:30 +02:00
Denys Vlasenko
12ffefb549 ash: more s/error/perror/ for better error reporting
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-23 14:52:56 +02:00
Johannes Schindelin
687aac056d ash: when cd fails, say why
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-23 14:48:25 +02:00
Johannes Schindelin
20a63b2c18 ash: report reason when a script file could not be opened
It is always nicer to give the user some sort of indication why an
operation failed.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-23 14:47:45 +02:00
Denys Vlasenko
fec2b1f79d ash: stage backported LINENO support as a separate patch
Looks biggish and not particularly useful, but may be easier to just eat
the impact if future backports from dash would be otherwise increasingly
difficult.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-17 16:43:33 +02:00
Denys Vlasenko
048491fbdc hush: trivial code shrink in builtin_getopts
function                                             old     new   delta
builtin_getopts                                      368     363      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-17 12:36:39 +02:00
Denys Vlasenko
9832bbaba9 ash: unset OPTARG if getopts exits 1, support OPTERR=0 behavior
function                                             old     new   delta
getoptscmd                                           522     547     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-15 15:44:41 +02:00
Denys Vlasenko
4476c70301 ash,hush: comment and debug tweaks, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-15 15:27:41 +02:00
Denys Vlasenko
0485b677d2 ash: one "current line = 1" might be missing, fix that
I'm not sure this is necessary, but dash has this init here.
Just in case, do it too.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-14 19:46:56 +02:00
Denys Vlasenko
c2aea025bb ash: update testsuite (we now error out on ${#=})
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-14 15:01:32 +02:00
Denys Vlasenko
452cc1d9bd ash: [PARSER] Catch variable length expansions on non-existant specials
Upstream commit:

    Date: Thu, 30 Oct 2014 11:53:35 +0800
    [PARSER] Catch variable length expansions on non-existant specials

    Currently we only check special variable names that follow directly
    after $ or ${.  So errors such as ${#&} are not caught.  This patch
    fixes that by moving the is_special check to just before we print out
    the special variable name.

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

function                                             old     new   delta
readtoken1                                          2630    2635      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-14 14:23:45 +02:00
Denys Vlasenko
007ce9f807 shell: tweak getopts tests, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-13 02:59:00 +02:00
Denys Vlasenko
419db0391e hush: implement "silent" optstrings of ":opts"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11 17:21:14 +02:00
Denys Vlasenko
129e1ce72c hush: add a test which fails due to uclibc bug in getopt()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11 17:00:39 +02:00
Denys Vlasenko
d16e612c93 hush: fix redirect code (was using uninitialized variables)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11 15:41:39 +02:00
Denys Vlasenko
9a7d0a0191 shell: add OPTARG poisoning to getopt_optarg.tests
ash fails this!

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11 02:37:48 +02:00
Denys Vlasenko
81f962f3df hush: teach getopts to set/unset OPTARG
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11 02:05:21 +02:00
Denys Vlasenko
74d4058928 hush: getopts builtin
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-11 01:32:46 +02:00
Denys Vlasenko
4628945cd8 ash: fix "unset OPTIND" throwing an error message
Added test was failing quite severely. Now only one subtest fails
(OPTERR=0 has no effect).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-11 00:59:36 +02:00
Denys Vlasenko
11f2e99c13 hush: optional times builtin
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-10 16:34:03 +02:00
Denys Vlasenko
cde46f75cb shell: more efficient check for EOL in read
function                                             old     new   delta
shell_builtin_read                                  1334    1320     -14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-09 14:04:07 +02:00
Denys Vlasenko
1f41c885fc hush: implement -d DELIM option for 'read'
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-09 13:52:36 +02:00
Johannes Schindelin
3bef5d89b0 ash: implement -d DELIM option for read
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.

It is also super easy to implement in BusyBox' ash, so let's do that.

The motivation: This option is used by Git's test suite.

function                                             old     new   delta
.rodata                                           163505  163587     +82
shell_builtin_read                                  1244    1289     +45
readcmd                                              233     259     +26
builtin_read                                         258     263      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 158/0)             Total: 158 bytes

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-09 13:52:17 +02:00
Denys Vlasenko
80e8e3cc05 noexec: consolidate code
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-07 19:24:57 +02:00
Denys Vlasenko
c9c1ccc4ed noexec: do GETOPT_RESET() before entering APPLET_main()
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-07 18:59:35 +02:00
Denys Vlasenko
f2cf1cc716 noexec: set comm field for noexecs
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-07 18:45:33 +02:00
Denys Vlasenko
248a67fb75 free,stat: make NOEXEC
pkill/pgrep/pidof uncovered another quirk: what about noexec's _process names_?

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-07 18:18:09 +02:00
Denys Vlasenko
0f14f41e72 ash: do not set a signal to SIG_DFL if it already is
function                                             old     new   delta
setsignal                                            312     338     +26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-06 20:06:19 +02:00
Denys Vlasenko
5c527dc57e make 17 state-changing execing applets (ex: "nice PROG ARGS") noexec
The applets with "<applet> [opts] PROG ARGS" API very quickly exec
another program, noexec is okay for them:

 chpst/envdir/envuidgid/softlimit/setuidgid
 chroot
 chrt
 ionice
 nice
 nohup
 setarch/linux32/linux64
 taskset
 cttyhack

"reset" and "sulogin" applets don't have this form, but also exec
another program at once, thus made noexec too.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 19:55:01 +02:00
Denys Vlasenko
f8cdc7a2bc ash: BASH_XTRACEFD bashism
Based on patch by Johannes Schindelin <johannes.schindelin@gmx.de>

function                                             old     new   delta
evalcommand                                         1447    1500     +53

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 15:24:49 +02:00
Johannes Schindelin
7344755823 ash: remove no-longer-used variable
As of 035486c75 (ash: significant overhaul of redirect saving logic,
2017-07-31), the sv_pos variable is no longer used (just assigned to,
with no further effect).

Let's just remove it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 14:52:08 +02:00
Denys Vlasenko
d329e34c96 ash: INT_OFF/INT_ON around run_nofork_applet()
function                                             old     new   delta
evalcommand                                         1441    1447      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 14:50:03 +02:00
Denys Vlasenko
49e6bf2db9 sheel: improve comments on signal handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 14:28:16 +02:00
Denys Vlasenko
cfd392bea9 ash: add a fixme comment at run_nofork_applet
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-03 19:56:29 +02:00
Denys Vlasenko
19c9f31af1 nofork: fix a bug uncovered by hush testsuite (forgotten fflush)
function                                             old     new   delta
run_nofork_applet                                    280     287      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-03 19:52:47 +02:00
Denys Vlasenko
39701204cf hush: do not accept "if() { echo; }" function def
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-02 19:46:14 +02:00
Denys Vlasenko
84ea60ed65 line editing: make read_line_input() not take timeout param
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-02 17:27:28 +02:00
Denys Vlasenko
dd4b446f76 hush: make SIGINT handling visually less confusing
$ 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-02 16:52:12 +02:00
Denys Vlasenko
7c40ddd950 NOFORK fixes
"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-08-02 16:37:39 +02:00
Denys Vlasenko
95f7953f2c do not use `a' quoting style in comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-02 14:26:33 +02:00
Denys Vlasenko
ec05df13b0 ash: align --login code with dash
Upstream commit:

    Date: Sun, 13 Jul 2008 22:34:50 +0800
    [OPTIONS] Added support for -l

    This patch adds support for the -l option (login shell) as required
    by the LSB.

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

It's a bit bigger, but gets rid of one global variable

function                                             old     new   delta
options                                              554     576     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 19:43:47 +02:00
Denys Vlasenko
cee603d921 hush: remove redundant "G_flag_return_in_progress = -1"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 18:06:07 +02:00
Denys Vlasenko
5b3d2eb327 hush: fix "true | func_with_return" not allowing return.
function                                             old     new   delta
pseudo_exec_argv                                     305     312      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 18:02:28 +02:00
Denys Vlasenko
d0fff9155b ash: fix display of ">&-" redirect in job strings
function                                             old     new   delta
cmdtxt                                               558     569     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 14:32:18 +02:00
Denys Vlasenko
75481d3634 hush: functions have priority over builtins (!)
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-31 05:27:09 +02:00
Denys Vlasenko
bf1c344dfd hush: if STANDALONE, close interactive fd for NOEXECed children
function                                             old     new   delta
pseudo_exec_argv                                     291     305     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 04:54:53 +02:00
Denys Vlasenko
32fdf2f9fc ash,hush: ">&10" redirects to script/tty fds should not work
The fact that shell has open fds to tty and/or scripts should be
unobservable, if possible. In particular, if redirect tries to dup
one of them via ">&script_fd", it's better to pretend that script_fd
is closed, and thus redirect fails with EBADF.

Fixes these two testcase failures:
ash-redir/redir_to_bad_fd.tests
hush-redir/redir_to_bad_fd3.tests

function                                             old     new   delta
redirect                                            1018    1129    +111
setup_redirects                                      250     359    +109
readtoken1                                          2651    2655      +4
cmdloop                                              185     187      +2
changepath                                           194     195      +1
save_fd_on_redirect                                  203     194      -9
evaltree                                             501     484     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/2 up/down: 227/-26)           Total: 201 bytes
   text    data     bss     dec     hex filename
 914553     485    6848  921886   e111e busybox_old
 914754     485    6848  922087   e11e7 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 04:35:18 +02:00
Denys Vlasenko
035486c750 ash: significant overhaul of redirect saving logic
New code is similar to what hush is doing.
Make CLOSED to -1: same as dash.
popredir() loses "restore" parameter: same as dash.
COPYFD_RESTORE bit is no longer necessary.

This change fixes this interactive bug:

	$ ls -l /proc/$$/fd 10>&-
	ash: can't set tty process group: Bad file descriptor
	ash: can't set tty process group: Bad file descriptor
	[1]+  Done(2)                    ls -l /proc/${\$}/fd 10>&4294967295

function                                             old     new   delta
unwindredir                                           29      27      -2
tryexec                                              154     152      -2
evaltree                                             503     501      -2
evalcommand                                         1369    1367      -2
cmdloop                                              187     185      -2
redirect                                            1029    1018     -11
popredir                                             153     123     -30
need_to_remember                                      36       -     -36
is_hidden_fd                                          68       -     -68
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/7 up/down: 0/-155)           Total: -155 bytes
   text    data     bss     dec     hex filename
 914572     485    6848  921905   e1131 busybox_old
 914553     485    6848  921886   e111e busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 04:21:46 +02:00
Denys Vlasenko
657e9005a9 hush: massage redirect code to be slightly more like ash
function                                             old     new   delta
save_fd_on_redirect                                    -     203    +203
xdup_CLOEXEC_and_close                                 -      75     +75
setup_redirects                                      245     250      +5
xdup_and_close                                        72       -     -72
save_fds_on_redirect                                 221       -    -221
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 1/0 up/down: 283/-293)          Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 04:08:09 +02:00
Denys Vlasenko
d07a15bd1b ash: remove REDIR_SAVEFD2
function                                             old     new   delta
evalcommand                                         1364    1369      +5
redirect                                            1055    1014     -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-41)             Total: -36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 04:05:51 +02:00
Denys Vlasenko
5f0a75f24b ash: if !ENABLE_ASH_EXPAND_PRMT, disable PSSYNTAX code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29 22:58:44 +02:00
Denys Vlasenko
1c79aeb6a8 ash: [REDIR] Fix popredir on abnormal exit from built-in
Upstream commit:

    Date: Thu, 27 May 2010 15:03:46 +0800
    [REDIR] Fix popredir on abnormal exit from built-in

    Just like the poplocalvar problem recently fixed, redirections
    can also be leaked in case of an abnormal exit.  This patch fixes
    it using the same method as poplocalvar, by storing the previous
    redirection state and restoring to that point.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29 22:51:52 +02:00
Denys Vlasenko
469998015f ash: [PARSER] Add FAKEEOFMARK for expandstr
Upstream commit:

    Date: Thu, 27 Dec 2007 13:54:16 +1100
    [PARSER] Add FAKEEOFMARK for expandstr

    Previously expandstr used the string "" to indicate that it needs to be
    treated just like a here-doc except that there is no terminator.  However,
    the string "" is in fact a valid here-doc terminator so now that we deal
    with it correctly expandstr no longer works in the presence of new-lines
    in the prompt.

    This patch introduces the FAKEEOFMARK macro which does not equal any
    real EOF marker but is distinct from the NULL pointer which is used to
    indicate non-here-doc contexts.

    Thanks to Markus Triska for reporting this regression.

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

Unfortunately, I did not find the failing example for this old fix.

I also tweaked the code which was added by this commit:
"
Date: Mon Sep 24 18:30:02 2007 +0000
ash: fix prompt expansion (Natanael Copa <natanael.copa@gmail.com>)
"
since other parts of code do expect expandstr() to use DQSYNTAX, not PSSYNTAX.

function                                             old     new   delta
parse_stream                                        2609    2634     +25
setprompt_if                                         128     133      +5
read_profile                                          32      37      +5
evalcommand                                         1334    1339      +5
expandstr                                            122     120      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 40/-2)              Total: 38 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29 21:12:29 +02:00
Denys Vlasenko
0f018b3070 hush: fix handling of empty heredoc EOF marker
function                                             old     new   delta
parse_stream                                        2609    2634     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29 20:43:26 +02:00
Denys Vlasenko
a732898fdd ash: [PARSER] Removed noexpand/length check on eofmark
Upstream comment:

	Date: Sun, 11 Nov 2007 14:21:23 +0800
	[PARSER] Removed noexpand/length check on eofmark

	On Tue, Oct 30, 2007 at 04:23:35AM +0000, Oleg Verych wrote:
	>
	> } 8<<""
	> ======================

	Actually this (the empty delim) only works with dash by accident.
	I've tried bash and pdksh and they both terminate on the first
	empty line which is what you would expect rather than EOF.  The
	real Korn shell does something completely different.

	I've fixed this in dash to conform to bash/pdksh.

	> In [0] it's stated, that delimiter isn't evaluated (expanded), only
	> quoiting must be checked. That if() seems to be completely bogus.

	OK I agree.  The reason it was there is because the parser would
	have already replaced the dollar sign by an internal representation.

	I've fixed it properly with this patch.

	Test case:

	        cat <<- $a
	                OK
	        $a

	        cat <<- ""
	                OK

	        echo OK

	Old result:

	        dash: Syntax error: Illegal eof marker for << redirection
	        OK

	        echo OK

	New result:

	        OK
	        OK
	        OK

function                                             old     new   delta
parsefname                                           227     152     -75
readtoken1                                          2819    2651    -168
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-243)           Total: -243 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29 19:57:28 +02:00
Denys Vlasenko
170f93ef1b ash: "Undo all redirections" comment is wrong, delete it
No code changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29 18:54:53 +02:00
Denys Vlasenko
00a1dbd230 ash: make tryexec(cmd) parameter const char
Fewer casts this way.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29 01:20:53 +02:00
Ron Yorston
be366e5afa ash: support platforms that don't have '%m' printf specifier
The '%m' conversion specifier prints an error message based on the
current value of 'errno'.  It is available in the GNU C library,
Cygwin (since 2012), uClibc and musl.

It is not available in various BSDs, BSD-derived systems (MacOS,
Android) or Microsoft Windows.

Use a symbol defined in platform.h to control how error messages
can be formatted to display the 'errno' message.  On platforms that
support it use '%m'; on other platforms use '%s' and strerror().

On platforms that have '%m' there is essentially no change in the
size of the binary.  Otherwise:

function                                             old     new   delta
redirect                                            1287    1310     +23
xtcsetpgrp                                            27      44     +17
dup2_or_raise                                         34      51     +17
setinputfile                                         267     275      +8
.rodata                                           163379  163371      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 65/-8)              Total: 57 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-28 15:39:26 +02:00
Denys Vlasenko
619d9b5e68 ash: less hackish implementation of evaltreenr()
Defining a function alias with __attribute__ ((alias("evaltree"),__noreturn__))
is not that usual, and clang had a bug which made it misunderstand
this construct.

Switch to:
ALWAYS_INLINE NORETURN evaltreenr() { evaltree(); unreachable(); }

Older gcc's do not know unreachable(), on them we pay the price of having
a few extra calls to abort():

function                                             old     new   delta
evalsubshell                                         151     156      +5
evalpipe                                             357     362      +5
argstr                                              1141    1144      +3

On newer gcc, code size does not change.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-28 15:28:33 +02:00
Denys Vlasenko
488e609203 ash: force inlining of a trivial function
function                                             old     new   delta
bltinlookup                                            5       -      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 23:08:36 +02:00
Denys Vlasenko
b8c0bc18f0 ash: revert previous implementation of "A=1 A=2 B=$A cmd" code
Reverts this:

    commit 0e6f661e23
    Date:   Fri Feb 15 15:02:15 2008 +0000
    ash: handle "A=1 A=2 B=$A; echo $B". closes bug 947.

A different fix from upstream has been imported by previous six commits.

Last seven commits, cumulative:

function                                             old     new   delta
poplocalvars                                           -     314    +314
mklocal                                                -     288    +288
pushlocalvars                                          -      48     +48
evalcommand                                         1372    1408     +36
unwindlocalvars                                        -      22     +22
ash_main                                            1022    1029      +7
setvar                                               167     172      +5
localvar_stack                                         -       4      +4
setvareq                                             303     302      -1
evalcase                                             271     269      -2
subevalvar                                          1202    1198      -4
localvars                                              4       -      -4
cmdenviron                                             4       -      -4
expandarg                                            984     973     -11
evalvar                                              589     574     -15
argstr                                              1164    1141     -23
dotcmd                                               335     303     -32
bltinlookup                                           51       5     -46
varvalue                                             709     596    -113
evalfun                                              456     270    -186
localcmd                                             364      44    -320
------------------------------------------------------------------------------
(add/remove: 5/2 grow/shrink: 3/11 up/down: 724/-761)         Total: -37 bytes
   text	   data	    bss	    dec	    hex	filename
 915353	    485	   6888	 922726	  e1466	busybox_old
 915320	    485	   6880	 922685	  e143d	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 23:03:21 +02:00
Denys Vlasenko
d04fc712e3 ash: [VAR] Fix loss of variables when hash collides
Upstream commit:

    Date: Tue, 6 Jul 2010 17:40:53 +0800
    [VAR] Fix loss of variables when hash collides

    Brian Koropoff reported that the new var patches broke the following
    script:

    #!/bin/dash
    GDM_LANG="bar"
    OPTION="foo"
    unset GDM_LANG
    # OPTION has mysteriously become unset
    echo "$OPTION"

    He correctly diagnosed this as a result of removing all variables
    in the hash chain preceding the one that should be removed in
    setvareq.

    He also provided a patch to fix this.

    This patch is based on his but without keeping the original vpp.
    As a result, we now store new variables at the end of the hash
    chain instead of the beginning.

    To make this work, setvareq/setvar now returns the vp pointer
    modified.  In case they're used to unset a variable the pointer
    returned is undefined.  This is because mklocal needs it and
    used to get it by assuming that the new variable always appear
    at the beginning of the chain.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 20:33:51 +02:00
Denys Vlasenko
85241c7b0b ash: [VAR] Do not poplocalvars prematurely on regular utilities
Upstream commit:

    Date: Thu, 27 May 2010 11:50:19 +0800
    [VAR] Do not poplocalvars prematurely on regular utilities

    The recent cmdenviron removal broke regular utilities by calling
    poplocalvars too early.  This patch fixes that by postponing the
    poplocalvars for regular utilities until they have completed.

    In order to ensure that local still works, it is now a special
    built-in.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 20:33:51 +02:00
Denys Vlasenko
484fc2056d ash: [VAR] Fix poplocalvar on abnormal exit from function
Upstream commit:

    Date: Thu, 27 May 2010 11:32:55 +0800
    [VAR] Fix poplocalvar on abnormal exit from function

    The new localvar code broke the abnormal exit from functions
    and built-ins by not restoring the original localvar state.

    This patch fixes this by storing the previous localvar state so
    that we always unwind correctly in case of an abnormal exit.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 20:33:51 +02:00
Denys Vlasenko
981a0568b3 ash: [VAR] Replace cmdenviron with localvars
Upstream commit:

    Date: Wed, 26 May 2010 18:54:19 +0800
    [VAR] Replace cmdenviron with localvars

    This patch replaces the cmdenviron mechanism for temporary command
    variables with the localvars mechanism used by functions.

    This reduces code size, and more importantly, makes the variable
    assignment take effect immediately as required by POSIX.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 20:33:51 +02:00
Denys Vlasenko
d5b500c81c ash: [VAR] Fix poplocalvar leak
Upstream commit:

    Date: Tue, 25 May 2010 18:14:32 +0800
    [VAR] Fix poplocalvar leak

    When a variable is marked as local, we set VSTRFIXED on its vp
    recored.  However, poplocalvar never clears this flag for variables
    that were unset to begin with.  Thus if you ever made an unset
    variable local, it would get the VSTRFIXED bit and stick around
    forever.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 20:33:51 +02:00
Denys Vlasenko
b8ab27bf53 ash: [VAR] Add localvars nesting
Upstream commit:

    Date: Mon, 24 May 2010 15:31:27 +0800
    [VAR] Add localvars nesting

    This patch adds localvars nesting infrastructure so we can reuse
    the localvars mechanism for command evaluation.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 20:33:51 +02:00
Denys Vlasenko
cf3a796dd1 ash: alloc slightly smaller buffer in cvtnum(); faster unsetvar()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 14:38:19 +02:00
Denys Vlasenko
b31b61bb9b ash: fix redir_leak.tests if STANDALONE=y
If STANDALONE and we run a NOEXEC applet, saved copies of redirected fds
were visible for the child. They have CLOEXEC bit, yes, but we do not exec
in this case.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 13:42:53 +02:00
Denys Vlasenko
b0648b0e78 shell: remove ${#+} tests, it is not a valid construct
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 00:30:02 +02:00
Denys Vlasenko
2093ad296f hush: fix ${##}, ${#?}, ${#!} handling
function                                             old     new   delta
parse_dollar                                         786     820     +34
expand_one_var                                      1579    1592     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 47/0)               Total: 47 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-26 00:07:27 +02:00
Denys Vlasenko
1e3e2ccd5d ash: [SHELL] Optimize dash -c "command" to avoid a fork
Upstream commit:

    Date: Thu, 7 Jul 2011 13:58:48 +0800
    [SHELL] Optimize dash -c "command" to avoid a fork

    On Sun, Apr 10, 2011 at 07:36:49AM +0000, Jonathan Nieder wrote:
    > From: Jilles Tjoelker <jilles@stack.nl>
    > Date: Sat, 13 Jun 2009 16:17:45 -0500
    >
    > This change only affects strings passed to -c, when the -s option is
    > not used.
    >
    > Use the EV_EXIT flag to inform the eval machinery that the string
    > being passed is the entirety of input.  This way, a fork may be
    > omitted in many special cases.
    >
    > If there are empty lines after the last command, the evalcmd will not
    > see the end early enough and forks will not be omitted. The same thing
    > seems to happen in bash.
    >
    > Example:
    >   sh -c 'ps lT'
    > No longer shows a shell process waiting for ps to finish.
    >
    > [jn: ported from FreeBSD SVN r194128.  Bugs are mine.]
    >
    > Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

    Instead of detecting EOF using the input layer, I'm going to
    use the parser instead.  In either case, we always have to read
    ahead in order to complete the parsing of the previous node.
    Therefore we always know whether there is more to come, except
    in the case where we see a newline/semicolon or similar.

    For the purposes of sh -c, this should be sufficient.

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

function                                             old     new   delta
evalstring                                           190     224     +34
ash_main                                            1014    1022      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 42/0)               Total: 42 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-25 20:31:14 +02:00
Denys Vlasenko
86981e3ad2 ash: allow "trap NUM [SIG]..." syntax
While at it, make get_signum() return -1 for numeric strings >= NSIG.

function                                             old     new   delta
trapcmd                                              292     306     +14
get_signum                                           295     300      +5
builtin_trap                                         413     412      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 19/-1)              Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-25 20:06:17 +02:00
Denys Vlasenko
f1a5cb0548 ash: [REDIR] Replace GPL noclobberopen code with the FreeBSD version
Upstream commit:

    Date: Thu, 10 Mar 2011 16:52:13 +0800
    [REDIR] Replace GPL noclobberopen code with the FreeBSD version

    Replace noclobberopen() from bash with the FreeBSD code for noclobber
    opens.

    This also reduces code size by eliminating an unnecessary check.

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

function                                             old     new   delta
changepath                                           192     194      +2
localcmd                                             366     364      -2
expmeta                                              521     517      -4
redirect                                            1210    1135     -75
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 2/-81)             Total: -79 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-25 17:47:48 +02:00
Denys Vlasenko
2990aa45d1 ash: sync up with dash with respect to redirection escaping
We fixed the problem differently than they. Let's not deviate.

Upstream commit:

    Date: Thu, 27 May 2010 20:07:29 +1000
    [EXPAND] Fix corruption of redirections with byte 0x81

    In other ash variants, a partial implementation of ksh-like cmd >file*
    adds and removes CTLESC bytes ('\x81') in redirection filenames,
    preserving 8-bit transparency. Long ago, dash removed the code to add
    the CTLESC bytes, but not the code to remove them, causing corruption of
    filenames containing CTLESC. This commit removes the code to remove the
    CTLESC bytes.

    The CTLESC byte occurs frequently in UTF-8 encoded non-Latin text.

    This bug has been reported various times to Ubuntu and Debian (e.g.
    Launchpad Ubuntu #422298). This patch is the same as the one submitted
    by Alexander Korolkov in Ubuntu #422298.

    Signed-off-by: Jilles Tjoelker <jilles@stack.nl>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
changepath                                           194     192      -2
expandarg                                           1000     984     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-25 17:37:57 +02:00
Denys Vlasenko
b28d4c3462 ash: [VAR] Move unsetvar functionality into setvareq
Upstream commit:

    Date: Tue, 25 May 2010 20:55:05 +0800
    [VAR] Move unsetvar functionality into setvareq

    This patch moves the unsetvar code into setvareq so that we can
    no have a pathological case of an unset variable hanging around
    unless it has a bit pinning it like VEXPORT.

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

function                                             old     new   delta
setvareq                                             227     303     +76
expmeta                                              517     521      +4
localcmd                                             364     366      +2
unsetcmd                                              96      76     -20
unsetvar                                             129       7    -122
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/2 up/down: 82/-142)           Total: -60 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-25 16:29:36 +02:00
Denys Vlasenko
be669fa1fd ash: import param_expand_default.tests from hush
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-25 15:25:07 +02:00
Denys Vlasenko
645c697372 hush: treat ${#?} as "length of $?"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-25 15:18:57 +02:00
Denys Vlasenko
64925384c9 ash: add a few tests from hush-vars/*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-25 14:55:05 +02:00
Denys Vlasenko
5c123ac208 ash: fix comment, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-24 20:03:24 +02:00
Denys Vlasenko
8d2191c6ae ash: copy three tests from hush_test/hush-signals/*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-24 19:42:46 +02:00
Denys Vlasenko
ca50caacad shell: some additions to *sh-misc/* tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-24 18:51:40 +02:00
Denys Vlasenko
4a1d8f6d6e ash: add most of hush process subst tests
ash passes these.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-24 12:49:49 +02:00
Denys Vlasenko
621fc50e83 hush: fix a case when redirect to a closed fd #1 is not restoring (closing) it
function                                             old     new   delta
setup_redirects                                      200     245     +45
append_squirrel                                        -      41     +41
save_fds_on_redirect                                 256     221     -35
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 86/-35)             Total: 51 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-24 12:42:17 +02:00
Denys Vlasenko
e34dbc4fdc ash: add all hush parsing tests to ast tests
All pass.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-24 02:49:56 +02:00
Denys Vlasenko
0675b03de4 hush: use mempcpy where useful
function                                             old     new   delta
o_addblock                                            58      42     -16
expand_one_var                                      1618    1555     -63
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-79)             Total: -79 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-24 02:17:05 +02:00
Denys Vlasenko
94af83eb8d ash: fix for last commit
"mempcpy(q, s, len) + len" is obviously no good :(

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-23 21:55:40 +02:00
Denys Vlasenko
5ace96a713 ash: use mempcpy() in more places
Most changes are taken from dash.

function                                             old     new   delta
single_quote                                         127     129      +2
stack_nputstr                                         28      29      +1
path_advance                                         209     202      -7
rmescapes                                            346     308     -38
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 3/-45)             Total: -42 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-23 21:46:34 +02:00
Denys Vlasenko
da2244fe48 ash: use mempcpy() where appropriate
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-21 18:51:29 +02:00
Denys Vlasenko
0eed355eac ash: suppress readonly1.tests false positive; add readonly0.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-21 13:37:25 +02:00
Denys Vlasenko
42ba757d5e ash: improve set -x to quote strings as necessary
Basen on the patch from Martijn Dekker <martijn@inlv.org>

function                                             old     new   delta
evalcommand                                         1161    1302    +141
maybe_single_quote                                     -      60     +60
getoptscmd                                           527     546     +19
readtoken1                                          2819    2823      +4
localcmd                                             366     364      -2
evaltreenr                                           495     479     -16
evaltree                                             495     479     -16
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/3 up/down: 224/-34)           Total: 190 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-21 13:20:14 +02:00
Denys Vlasenko
72089cf6b4 config: deindent all help texts
Those two spaces after tab have no effect, and always a nuisance when editing.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-21 09:50:55 +02:00
Denys Vlasenko
eae12688c9 shell: optional support for read -t N.NNN, closes 10101
function                                             old     new   delta
shell_builtin_read                                  1097    1277    +180
dump_procs                                           353     359      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-20 16:09:31 +02:00
Denys Vlasenko
8ecd861406 ash: remove contradicting size info in config help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 22:25:12 +02:00
Denys Vlasenko
f9d656f787 hush: remove contradicting size info in config help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 22:23:55 +02:00
Denys Vlasenko
4eed2c6c50 Update menuconfig items with approximate applet sizes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 22:01:24 +02:00
Denys Vlasenko
d2c15bc763 hush: tweak "help" output
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 18:14:42 +02:00
Denys Vlasenko
cf5110978b hush: fix readonly2.tests failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 15:58:02 +02:00
Denys Vlasenko
f645e1573c hush: another testcase for "READONLY_VAR=VAL BLTIN ..."
Currently fails.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 03:23:07 +02:00
Denys Vlasenko
5b2cc0aaee hush: do not assign to readonly VAR in "VAR=VAL CMD" syntax too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 02:44:06 +02:00
Denys Vlasenko
38ef39a1ab hush: add readonly testcase, fix fallout
function                                             old     new   delta
helper_export_local                                  185     214     +29
run_pipe                                            1549    1560     +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0)               Total: 40 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 01:40:01 +02:00
Denys Vlasenko
3bab36b18b hush: convert exp/ro/local parameters to bitfields in one flag param
function                                             old     new   delta
helper_export_local                                  174     185     +11
set_local_var                                        424     420      -4
run_list                                            1048    1044      -4
set_vars_and_save_old                                 88      83      -5
set_local_var_from_halves                             27      22      -5
run_pipe                                            1554    1549      -5
builtin_export                                       173     168      -5
set_pwd_var                                           40      34      -6
builtin_readonly                                      70      64      -6
expand_one_var                                      1625    1618      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/9 up/down: 11/-47)            Total: -36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 01:05:24 +02:00
Denys Vlasenko
6b0695bb66 hush: HUSH_READONLY depends on HUSH
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-17 21:47:27 +02:00
Denys Vlasenko
6b48e1f121 hush: forgot to emit error on (failing) second "readonly VAR=VAL"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-17 21:31:17 +02:00
Denys Vlasenko
b95ee96e75 hush: smaller code in !READONLY configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-17 21:19:53 +02:00
Denys Vlasenko
1e660422b1 hush: implement "readonly" builtin
function                                             old     new   delta
builtin_readonly                                       -      70     +70
helper_export_local                                  152     174     +22
bltins1                                              348     360     +12
expand_one_var                                      1620    1625      +5
builtin_export                                       168     173      +5
set_pwd_var                                           36      40      +4
set_local_var                                        410     414      +4
set_vars_and_save_old                                 85      88      +3
set_local_var_from_halves                             24      27      +3
run_pipe                                            1551    1554      +3
run_list                                            1046    1048      +2
builtin_type                                         116     114      -2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 10/1 up/down: 133/-2)           Total: 131 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-17 21:10:50 +02:00
Denys Vlasenko
826360ff23 ash: more general format ${var:EXPR:EXPR}
function                                             old     new   delta
subevalvar                                          1171    1202     +31
localcmd                                             364     366      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-17 17:49:11 +02:00
Denys Vlasenko
4f8079de87 ash: "you disabled math" is wrong: user did not disable it, builder of ash did
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-17 17:11:48 +02:00
Denys Vlasenko
0ba80e4fa2 hush: small fix to last commit
die_if_script() indeed dies only in scripts! Must handle the case where it continues.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-17 16:50:20 +02:00
Denys Vlasenko
e32b6503e7 hush: support ${VAR:N:-M}
function                                             old     new   delta
expand_one_var                                      1602    1615     +13
builtin_type                                         114     116      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-17 16:46:57 +02:00
Denys Vlasenko
203fd7bc66 shells: expand TODO comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-17 16:13:35 +02:00
Denys Vlasenko
b24e55da84 hush: fix "cmd1 && cmd2 &" handling on NOMMU
function                                             old     new   delta
done_pipe                                            234     238      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-16 20:29:35 +02:00
Denys Vlasenko
9f904a22ff shell: and_or_and_backgrounding.tests is no longer "UNFIXED BUG"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-15 22:54:46 +02:00
Denys Vlasenko
ee553b929c hush: fix and_or_and_backgrounding.tests failure
function                                             old     new   delta
done_pipe                                            133     218     +85

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-15 22:51:55 +02:00
Johannes Schindelin
9d4dc84a76 ash: protect WIFSTOPPED use with #if JOBS
This change fixes the build in setups where there are
no headers defining WIFSTOPPED and WSTOPSIG (where JOBS has to be
set to 0).

This partially reverts 4700fb5be (ash: make dowait() a bit more
readable. Logic is unchanged, 2015-10-09).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-15 11:38:00 +02:00
Denys Vlasenko
2ed74e25d3 hush: make "wait %1" work even if the job is dead
Example script:

	sleep 1 | (sleep 1;exit 3) &
	sleep 2
	echo Zero:$?
	wait %1
	echo Three:$?

function                                             old     new   delta
clean_up_last_dead_job                                 -      24     +24
process_wait_result                                  426     447     +21
builtin_wait                                         285     293      +8
insert_job_into_table                                264     269      +5
builtin_jobs                                          68      73      +5
remove_job_from_table                                 59      57      -2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/1 up/down: 63/-2)              Total: 61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-14 19:58:46 +02:00
Denys Vlasenko
0c5657e911 hush: remove superfluous comparison
function                                             old     new   delta
builtin_wait                                         291     285      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-14 19:27:03 +02:00
Denys Vlasenko
9fda609a60 hush: add support for "set -e"
function                                             old     new   delta
run_list                                             978    1046     +68
o_opt_strings                                         24      32      +8
reset_traps_to_defaults                              136     142      +6
pick_sighandler                                       57      60      +3
packed_usage                                       31772   31770      -2
hush_main                                            983     961     -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/2 up/down: 85/-24)             Total: 61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-14 13:36:48 +02:00
Denys Vlasenko
b057806a6a hush: add TODO for "set -e"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-10 10:33:27 +02:00
Denys Vlasenko
9e55a156f8 hush: simplify insert_job_into_table() a bit
function                                             old     new   delta
done_word                                            767     761      -6
insert_job_into_table                                325     264     -61
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 59/-126)           Total: -67 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-10 10:01:12 +02:00
Denys Vlasenko
1609629a91 hush: rename a few functions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-10 10:00:28 +02:00
Denys Vlasenko
13102634bb hush: explain why wait5.tests is failing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-08 00:24:32 +02:00
Denys Vlasenko
840a4355d0 hush: fix "(sleep 1; exit 3) & sleep 2; echo $?; wait $!; echo $?"
function                                             old     new   delta
process_wait_result                                  414     426     +12
builtin_wait                                         283     291      +8
run_list                                             974     978      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 24/0)               Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-07 22:56:02 +02:00
Denys Vlasenko
2db74610cd hush: fix two redirection testcase failures
function                                             old     new   delta
save_fds_on_redirect                                 183     256     +73
fcntl_F_DUPFD                                          -      46     +46
restore_redirects                                     74      96     +22
xdup_and_close                                        51      72     +21
setup_redirects                                      196     200      +4
hush_main                                            988     983      -5
static.C                                              12       -     -12
run_pipe                                            1595    1551     -44
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 4/2 up/down: 166/-61)           Total: 105 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-07 22:07:28 +02:00
Denys Vlasenko
69a5ec9dcc main: fix the case where user has "halt" as login shell. Closes 9986
halt::0:0::/:/sbin/halt

function                                             old     new   delta
run_applet_and_exit                                  748     751      +3
run_applet_no_and_exit                               467     459      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-07 19:08:56 +02:00
Denys Vlasenko
111cdcf295 shell: sync redir/* tests
Note: hush-redir/redir_to_bad_fd.tests currently fails

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 21:01:50 +02:00
Denys Vlasenko
1ff1a75710 ash: rename redir5.tests (hush has redir5.tests which is different)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 21:00:19 +02:00
Denys Vlasenko
50b8b2914b hush: add a TODO about redir3.tests failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 20:57:37 +02:00
Denys Vlasenko
a107ef2a6a hush: rename hush-redir/redir3.tests (ash has redir3.tests which id different)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 20:36:40 +02:00
Denys Vlasenko
e59591a364 hush: Print error messages on shift -1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 20:12:44 +02:00
Denys Vlasenko
74d20e6379 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 19:50:42 +02:00
Denys Vlasenko
5dad7bdc3b hush: implement negative start in the ${v: -n[:m]} idiom
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 19:48:20 +02:00
Denys Vlasenko
3234045d07 hush: "adopt" ash var-utf8-length.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 19:29:23 +02:00
Denys Vlasenko
7456298472 hush: "adopt" ash signal4.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 18:40:45 +02:00
Denys Vlasenko
b18b04c8a8 shell: remove duplicate sigint1.tests (another copies are in signals/)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 18:37:30 +02:00
Denys Vlasenko
cafb2d195d hush: add tickquote1.tests from ash testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 18:31:47 +02:00
Denys Vlasenko
bb963bda62 shell: syncronize ash and hush heredoc3.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 18:19:35 +02:00
Denys Vlasenko
959cb67428 shell: syncronize ash and hush heredoc1.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 18:16:18 +02:00
Denys Vlasenko
9a8ece5158 shell: syncronize ash_test/run-all and hush_test/run-all a bit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 17:59:25 +02:00
Denys Vlasenko
637982f5bb hush: correctly handle quoting in "case" even if !BASH_PATTERN_SUBST
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 01:52:23 +02:00
Denys Vlasenko
bd43c6784f hush: fix quoted_punct.tests failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-05 23:12:15 +02:00
Denys Vlasenko
4142f0187d ash: fix escaping of a few characters (broken by last commits)
Add a testcase which tests all ASCII punctuation escapes.
NB: hush is failing this test!

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-05 22:19:28 +02:00
Denys Vlasenko
ed79a63623 ash: tweak in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-05 19:20:43 +02:00
Denys Vlasenko
92b8d9c9fa ash: note which versions of glibc exhibit "rho bug"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-05 19:13:44 +02:00
Denys Vlasenko
fda9fafe27 ash: fix matching of unicode greek letter rho (cf 81) and similar cases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-05 19:10:21 +02:00
Denys Vlasenko
d4e4fdb5ce fixes for bugs found by make_single_applets.sh
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-03 21:31:16 +02:00
Denys Vlasenko
2e989ef232 msh: delete this applet
It's deprecated since 2009 and interferes with make_single_applets.sh tests.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-03 16:56:37 +02:00
Denys Vlasenko
4ee824f6ba randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-03 01:22:13 +02:00
Denys Vlasenko
48c803a206 ash: fix $HOME/.profile reading if !ASH_EXPAND_PRMT, take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-01 23:26:12 +02:00
Denys Vlasenko
e9aba3e7ea ash: fix 'trap - 65'
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-01 21:09:27 +02:00
Denys Vlasenko
f56ddf2e4c ash: fix $HOME/.profile reading if !ASH_EXPAND_PRMT
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-27 17:51:07 +02:00
Youfu Zhang
6683d1cbb4 ash: fix incorrect path in describe_command
$ PATH=/extra/path:/usr/sbin:/usr/bin:/sbin:/bin \
> busybox sh -xc 'command -V ls; command -V ls; command -Vp ls; command -vp ls'
+ command -V ls
ls is /bin/ls
+ command -V ls
ls is a tracked alias for /bin/ls
+ command -Vp ls
ls is a tracked alias for (null)
+ command -vp ls
Segmentation fault

describe_command should respect `path' argument. Looking up in the hash table
may gives incorrect index in entry.u.index and finally causes incorrect output
or SIGSEGV.

function                                             old     new   delta
describe_command                                     386     313     -73

Signed-off-by: Youfu Zhang <zhangyoufu@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-26 17:37:35 +02:00
Denys Vlasenko
f547041940 ash,hush: fix SIGCHLD interrupting read builtin
function                                             old     new   delta
readcmd                                              169     217     +48
shell_builtin_read                                  1087    1097     +10
localcmd                                             366     364      -2
builtin_read                                         197     193      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 58/-6)              Total: 52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-22 19:34:45 +02:00
Denys Vlasenko
10ad622dc2 Spelling fixes in comments, documentation, tests and examples
By klemens <ka7@github.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-17 16:13:32 +02:00
Denys Vlasenko
6c149f4d9a ash: implement "exec -a ARGV0 CMD ARGV1..."
function                                             old     new   delta
execcmd                                               71     112     +41
shellexec                                            221     224      +3
evalcommand                                         1158    1161      +3
localcmd                                             364     366      +2
unaliascmd                                           163     154      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 49/-9)              Total: 40 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 21:31:32 +02:00
Denys Vlasenko
e139ae307e ash: make shellexec capable of using separate argv[0] and filename to exec
function                                             old     new   delta
execcmd                                               71      78      +7
shellexec                                            221     224      +3
evalcommand                                         1158    1161      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 21:02:33 +02:00
Kaarle Ritvanen
835ad3a984 libbb: GETOPT_RESET macro
Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 20:11:34 +02:00
Denys Vlasenko
5f7c82b32f ash: add INT_OFF/ON around allocations
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-03 13:00:06 +01:00
Felix Fietkau
b5b21126ca ash: improve / fix glob expansion
When using musl libc glob() a very long string can cause glob() to fail,
which leads to an out of memory error being raised by ash.

This can happen easily if a very long quoted string contains *, even
though no glob expansion should ever be performed on it (since it's
quoted).

Fix this by properly parsing control characters and escaping and only
accept unquoted metacharacters. While we're at it, unify this check for
libc and built-in glob expansion

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-31 21:58:55 +01:00
Denys Vlasenko
67f6db6b27 wget: add a big explanation what TLS code implements and what does not
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-30 16:27:37 +01:00
Denys Vlasenko
205d48e948 *: add comment about APPLET_ODDNAME format
It confused me more than once

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-29 14:57:33 +01:00
Denys Vlasenko
786c9dc0c1 sh: fix FEATURE_SH_STANDALONE help text: it does not enable NOFORK
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-26 18:31:51 +01:00
Denys Vlasenko
098b713c7b ash: commented-out possible fix for 7694
bash has a feature: it restores termios after a successful wait for
a foreground job which had at least one stopped or sigkilled member.
The probable rationale is that SIGSTOP and SIGKILL can preclude task from
properly restoring tty state. Should we do this too?
A reproducer: ^Z an interactive python:

$ python
Python 2.7.12 (...)
>>> ^Z
    { python leaves tty in -icanon -echo state. We do survive that... }
 [1]+  Stopped                    python
    { ...however, next program (python no.2) does not survive it well: }
$ python
Python 2.7.12 (...)
>>> Traceback (most recent call last):
    { above, I typed "qwerty<CR>", but -echo state is still in effect }
  File "<stdin>", line 1, in <module>
NameError: name 'qwerty' is not defined

The implementation is modeled on bash code and seems to work.
However, I'm not sure we should do this. For one: what if I'd fg
the stopped python instead? It'll be confused by "restored" tty state.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 19:59:03 +01:00
Denys Vlasenko
4c179373e0 ash: 16-bit ->nprocs field is a pain for many CPUs
function                                             old     new   delta
getoptscmd                                           527     540     +13
getjob                                               280     286      +6
makejob                                              278     282      +4
forkchild                                            602     600      -2
waitcmd                                              208     205      -3
showjob                                              382     379      -3
getstatus                                             83      80      -3
dowait                                               408     405      -3
freejob                                               93      89      -4
fg_bgcmd                                             290     286      -4
forkshell                                            260     255      -5
killcmd                                              224     218      -6
jobno                                                 17      11      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/10 up/down: 23/-39)           Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 18:44:15 +01:00
Denys Vlasenko
01ccdd1d3c libbb: consolidate the code to set termios unbuffered mode
function                                             old     new   delta
set_termios_to_raw                                     -     116    +116
count_lines                                           72      74      +2
powertop_main                                       1458    1430     -28
top_main                                             943     914     -29
more_main                                            759     714     -45
fsck_minix_main                                     2969    2921     -48
conspy_main                                         1197    1135     -62
rawmode                                               99      36     -63
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/6 up/down: 118/-275)         Total: -157 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 16:17:59 +01:00
Denys Vlasenko
8944c67b1f hush: reinstate [[ builtin
Mike deleted it:

    commit 39456a18a1
    Author: Mike Frysinger <vapier@gentoo.org>
    Date:   Sat Mar 28 12:21:57 2009 +0000

    stop lying about [[ test support

probably because it was not properly ifdefed around, and was enabled
even when bash compat is off.

I just tested it - it works:

$ [ *.diff = z.diff ]; echo $?
0
$ [[ *.diff = z.diff ]]; echo $?
1

Of course, not all numerous bash tricks of [[ ]] are implemented...

function                                             old     new   delta
bltins2                                               60      72     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 14:22:00 +01:00
Kang-Che Sung
027d3ab57d hush: split bash compatible extensions into separate defines. No code changes
Splitting these options makes it self-documenting about what
bash-compatible features we have.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 14:18:30 +01:00
Denys Vlasenko
7d4aec0c3e ash: split bash compatible extensions into separate defines. No code changes
Splitting these options makes it self-documenting about what
bash-compatible features we have.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 14:00:38 +01:00
Denys Vlasenko
80f806cac9 hush: shorten output of "help" builtin
text	   data	    bss	    dec	    hex	filename
 891272	    485	   6856	 898613	  db635	busybox_old
 891232	    485	   6856	 898573	  db60d	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 16:51:10 +01:00
Denys Vlasenko
a1184af5f8 hush: reorder builtins (cd and pwd ought to be close, etc), no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 15:58:02 +01:00
Denys Vlasenko
2b4c258e74 ash: revert "make dot command search current directory first"
Reverts this:
    commit 8ad78e1ec7
    Author: Denis Vlasenko <vda.linux@googlemail.com>
    Date:   Sun Feb 15 12:40:30 2009 +0000
    ash: make dot command search current directory first, as bash does.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 15:18:38 +01:00
Denys Vlasenko
265062d59d shells: make hush test optional, rename ASH_BUILTIN_foo -> ASH_foo
This makes hash and ash more symmetrical wrt config menu and config
options.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 15:13:30 +01:00
Denys Vlasenko
f560422fa0 Big cleanup in config help and description
Redundant help texts (one which only repeats the description)
are deleted.

Descriptions and help texts are trimmed.

Some config options are moved, even across menus.

No config option _names_ are changed.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 14:58:54 +01:00
Denys Vlasenko
1cc6804f69 hush: make echo builtin optional
It's a bit overkill (who would want it off?) but ash already has it
configurable. Let's be symmetric.

Also tweak kbuild logic to use ASH_BUILTIN_ECHO to select echo.o,
not ASH.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 17:10:04 +01:00
Denys Vlasenko
fb87d93d1e ash: fix a bug in argv restoration after sourcing a file
if sourced file "shift"ed argvs so that $1 is NULL, restore wasn't done.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 08:22:06 +01:00
Denys Vlasenko
2b1559056c hush: fix a bug in argv restoration after sourcing a file
if sourced file "shift"ed argvs so that $1 is NULL, restore wasn't done.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 08:13:21 +01:00