Commit Graph

341 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Denys Vlasenko
86584e134e ash: fix open fds leaking in redirects. Closes 9561
commit e19923f665 deleted clearredir()
call in shellexec():

	ash: [REDIR] Remove redundant CLOEXEC calls
	Upstream commit:

	Now that we're marking file descriptors as CLOEXEC in savefd, we no longer
	need to close them on exec or in setinputfd.

but it missed one place where we don't set CLOEXEC. Fixing this.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-07 10:16:56 +01:00
Ron Yorston
ea7d2f6ec0 ash: fix error code regression
The commit 'ash,hush: set exit code 127 in "sh /does/not/exist" case'
only partly implemented the dash commit '[ERROR] Allow the originator
of EXERROR to set the exit status'.  This resulted in incorrect error
codes for a syntax error:

   $ )
   $ echo $?
   0

or a redirection error for a special builtin:

   $ rm -f xxx
   $ eval cat <xxx
   $ echo $?
   0

Signed-off-by: Ron Yorston <rmy@pobox.com>
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-03 11:18:23 +01:00
Denys Vlasenko
02affb4afd hush: rework "wait %jobspec" to work in non-interactive shells too
Also add tests. wait5.tests so far fails (but works for ash and dash).

function                                             old     new   delta
builtin_wait                                         305     283     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 00:59:29 +01:00
Denys Vlasenko
672a55e606 hush: allow { cmd } to not be terminated by semicolon in some cases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-04 18:46:14 +01:00
Denys Vlasenko
7e6753609d hush: fix "wait PID"
It was not properly interruptible, and did not update job status
(the exited processes were still thought of as running).

function                                             old     new   delta
process_wait_result                                    -     453    +453
wait_for_child_or_signal                               -     199    +199
run_list                                             996    1002      +6
checkjobs_and_fg_shell                                41      43      +2
builtin_wait                                         328     215    -113
checkjobs                                            516     142    -374
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/2 up/down: 660/-487)          Total: 173 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-28 21:59:09 +02:00
Denys Vlasenko
350e686f3b ash: [PARSER] Recognise here-doc delimiters terminated by EOF
Upstream commit 1:

    Date: Wed, 26 Sep 2007 17:14:16 +0800
    [PARSER] Recognise here-doc delimiters terminated by EOF

    Previously dash required a <newline> character to be present in order for
    a here-document delimiter to be detected.  Allowing EOF in the absence of
    a <newline> to play the same purpose allows some intuitive scripts to
    succeed.  POSIX seems to be silence on this so this should be OK.

    Test case:

        eval 'cat <<- NOT
                test
        NOT'
        echo OK

    Old result:

        test
        NOTOK

    New result:

        test
        OK

Upstream commit 2:

    Date: Sat, 20 Oct 2007 18:49:31 +0800
    [PARSER] Fix here-doc corruption

    The change

        [PARSER] Recognise here-doc delimiters terminated by EOF

    introduced a regerssion whereby lines starting with eofmark but are not equal
    to eofmark would be corrupted.  This patch fixes it.

    Test case:

        cat << _ACEOF
        _ASBOX
        _ACEOF

    Old result:

        SASBOX

    New result:

        _ASBOX

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 16:26:45 +02:00
Denys Vlasenko
f15aa57a7f ash: [PARSER] Fix parsing of ${##1}
Upstream commit:

    Date: Thu, 4 Oct 2007 22:15:10 +0800
    [PARSER] Fix parsing of ${##1}

    Previously dash treated ${##1} as a length operation.  This patch fixes that.

    Test case:

        set -- a
        echo ${##1}OK

    Old result:

        1OK

    New result:

        OK

This was a real bug in ash (but not in hush).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 15:56:53 +02:00
Denys Vlasenko
4135a75ab0 typo fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 13:15:35 +02:00
Denys Vlasenko
c775f829db sh testsuite: add tests for exitcode on failure to exec
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:55:34 +02:00
Denys Vlasenko
9793fc576a hush testsuite: fix another false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:14:26 +02:00
Denys Vlasenko
d3b4e5ec6a hust testsuite: fix a false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:10:20 +02:00
Denys Vlasenko
a62bc80571 ash testsuite: add most of hust tests which pass for ash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:06:55 +02:00
Denys Vlasenko
db7f4c203b hush: add var4.tests, var5.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 21:13:13 +02:00
Denys Vlasenko
61508d9624 hush: fix var3.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 21:12:02 +02:00
Denys Vlasenko
df303ae117 sh testsuite: sync ash-redir/ and hush-redir/
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 18:32:52 +02:00
Denys Vlasenko
c7a774dde4 sh testsuite: sync ash-misc/source* and hush-misc/source*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 18:23:14 +02:00
Denys Vlasenko
0ba99705a1 sh testsuite: sync ash-vars/ and hush-vars/
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 18:17:15 +02:00
Denys Vlasenko
c4cf542c57 sh testsuite: create hush-redir/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:55:51 +02:00
Denys Vlasenko
1b73f8471a sh testsuite: create hush-heredoc/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:49:46 +02:00
Denys Vlasenko
5d6b8729ed hush testsuite: add many tests from ash testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:39:31 +02:00
Denys Vlasenko
ae4bd34e6b hush testsuite: add glob_dir.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 15:20:57 +02:00
Denys Vlasenko
0aaaa50b45 ash: expand: Fixed "$@" expansion when EXP_FULL is false
Upstream commit:

    Date: Thu, 1 Jan 2015 07:53:10 +1100
    expand: Fixed "$@" expansion when EXP_FULL is false

    The commit 3c06acdac0b1ba0e0acdda513a57ee6e31385dce ([EXPAND]
    Split unquoted $@/$* correctly when IFS is set but empty) broke
    the case where $@ is in quotes and EXP_FULL is false.

    In that case we should still emit IFS as field splitting is not
    performed.

    Reported-by: Juergen Daubert <jue@jue.li>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 02:46:56 +02:00
Denys Vlasenko
ff59b7b112 ash,hush: add a test that "continue" does not cripple traps
Both shells pass this test.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 23:28:02 +02:00
Denys Vlasenko
3ed7e2749a ash testsuite: add return_in_trap1.tests
Currently it fails

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 22:36:14 +02:00
Denys Vlasenko
04b46bced9 hush: 'return' should have effect earlier
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 22:28:03 +02:00
Denys Vlasenko
88ac97d02d ash: [EXPAND] Do not split quoted VSLENGTH and VSTRIM
Upstream patch:

    Date: Wed, 8 Oct 2014 15:42:08 +0800
    [EXPAND] Do not split quoted VSLENGTH and VSTRIM

    Currently VSLENGTH and VSTRIM* are field-split even within quotes.
    This is obviously wrong.  This patch fixes that.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 20:55:02 +02:00
Denys Vlasenko
c4d4380a07 ash: [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty
Upstream commit:

    Date: Wed, 8 Oct 2014 15:24:23 +0800
    [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty

    Currently we do not field-split $@/$* when it isn't quoted and IFS
    is set but empty.  This is obviously wrong.  This patch fixes this.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 20:35:10 +02:00
Denys Vlasenko
a2633aa819 hush: add func6.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 20:12:10 +02:00
Denys Vlasenko
7a24e8ffeb shell testsuite: add trailing newline to var_unbackslash1.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 20:02:53 +02:00
Denys Vlasenko
459293b1c5 ash: fix arithmetic closing )) split by backslash-newline
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 17:58:58 +02:00
Denys Vlasenko
8286513838 hush: rework input char buffering to allow more than one-deep peek
This fixes backslash+newline continuation in
	$VAR\
	NAME
construct. (ash has a bug there as well).

function                                             old     new   delta
file_peek2                                             -      74     +74
parse_dollar                                         746     773     +27
expand_vars_to_list                                 1143    1167     +24
setup_string_in_str                                   32      46     +14
setup_file_in_str                                     33      47     +14
file_get                                             264     278     +14
static_peek2                                           -       7      +7
file_peek                                             91      72     -19
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/1 up/down: 174/-19)           Total: 155 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 16:59:06 +02:00
Denys Vlasenko
78c9c736ab hush: fix 'eval ""' handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 01:44:17 +02:00
Denys Vlasenko
992e0ff7e9 hush: fix ". EMPTY_LINE" not setting $? to 0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 01:27:09 +02:00
Denys Vlasenko
928e2a7ef4 ash: [EVAL] Make eval with empty arguments return 0
This is a backport of upstream commit:

    [EVAL] Make eval with empty arguments return 0

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 00:30:31 +02:00
Denys Vlasenko
eb17b6f6c9 ash: eval: Return status in eval functions
Backported from dash:

    eval: Return status in eval functions

    The exit status is currently clobbered too early for case statements
    and loops.  This patch fixes it by making the eval functions return
    the current exit status and setting them in one place -- evaltree.

    Harald van Dijk pointed out a number of bugs in the original patch.

function                                             old     new   delta
evalcommand                                         1226    1242     +16
cmdloop                                              383     398     +15
evalfor                                              223     227      +4
evalcase                                             271     275      +4
localcmd                                             348     350      +2
evaltreenr                                           927     928      +1
evaltree                                             927     928      +1
evalsubshell                                         150     151      +1
evalpipe                                             356     357      +1
parse_command                                       1585    1584      -1
evalloop                                             177     164     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 9/2 up/down: 45/-14)             Total: 31 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-28 19:41:57 +02:00
Denys Vlasenko
aa3576a29b hush: fix "redirects can close script fd" bug
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-22 19:54:12 +02:00
Denys Vlasenko
215b0ca6e4 hush: fix a bug in FEATURE_SH_STANDALONE=y config. Closes 9186
Run this in a "sh SCRIPT":

sha256sum /dev/null
echo END

sha256sum is a NOEXEC applet. It runs in a forked child. Then child exit()s.
By this time, entire script is read, and buffered in a FILE object
from fopen("SCRIPT"). But fgetc() did not consume entire input.
exit() lseeks back by -9 bytes, from <eof> to 'e' in 'echo'.
(this may be libc-specific).
This change of fd position *is shared with the parent*!

Now parent can read more, and it thinks there is another "echo END".
End result: two "echo END"s are run.

Fix this by _exit()ing instead.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-19 18:43:06 +02:00
Denys Vlasenko
bc9bee01f3 hush-misc/func_args1.tests: remove "UNFIXED BUG", it does not fail
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 14:50:19 +01:00
Denys Vlasenko
112889d706 hush: copy for.tests from ash testsuite
This test passes for hush

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 22:37:25 +01:00
Denys Vlasenko
450a367a11 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 01:49:06 +02:00
Denys Vlasenko
b5be13ccd9 hush: fix a nommu bug where a part of function body is lost if run in a pipe
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 06:22:10 +02:00
Denys Vlasenko
26c423d9a8 ash,hush: add a test which fails for ash since commit 549deab
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 03:33:02 +02:00
Denys Vlasenko
9a595bb36d hush: add recent ash tests to hush testsuite too (they all pass for hush)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 10:23:16 +02:00
Denys Vlasenko
73327a048b hush: document buggy handling of duplicate "local"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-18 19:38:13 +02:00
Denys Vlasenko
c538d5bcc3 hush: make ${#var} unicode-aware
This mimics bash

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-13 09:57:44 +02:00
Denys Vlasenko
3beab83e4f hush: fix for "while false && true; do echo BUG; break; done". closes 6170
function                                             old     new   delta
run_list                                             959     941     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-04-07 18:16:58 +02:00
Denys Vlasenko
88b532d59a hush: source builtin should override $N only if it has args
function                                             old     new   delta
builtin_source                                       174     184     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-17 14:11:04 +01:00
Denys Vlasenko
6e42b89b8d hush: fix remaining known two bugs with IFS expansion. Closes 4027.
function                                             old     new   delta
expand_vars_to_list                                 1054    1140     +86
parse_stream                                        2425    2479     +54
expand_on_ifs                                        258     310     +52
builtin_umask                                        133     132      -1
done_word                                            820     779     -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/2 up/down: 192/-42)           Total: 150 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-08-01 18:16:43 +02:00
Denys Vlasenko
4fb53fb08c hush: partially fix wrong expansion on $IFS (bug 4027).
In the added testcase, before patch we failed 8 out of 9 tests,
now we fail only 2 (4th and 5th).

function                                             old     new   delta
expand_on_ifs                                        225     258     +33
expand_vars_to_list                                 1038    1054     +16
o_save_ptr_helper                                    115     119      +4
builtin_umask                                        132     133      +1
o_addQstr                                            165     161      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 54/-4)              Total: 50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-08-01 14:06:20 +02:00
Denys Vlasenko
00ae989ee5 hush: fix a corner case of empty "do \n done" structure
The structure is:

    while cmd; do
    done

bash doesn't accept it at all. We were accepting it but execution
was buggy.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-05-31 17:35:45 +02:00
Denys Vlasenko
29f9b7268a hush: fix misparsing of "... do eval a= ...". Closes 3721
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-05-14 11:27:36 +02:00
Denys Vlasenko
bcf1fa80f3 hush: add tests for interrupting read
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-05-09 01:05:33 +02:00
Denys Vlasenko
c162bcdcd1 hush: document a bug about aborting on sourced file error when non-interactive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-03-24 05:38:51 +01:00
Denys Vlasenko
68d5cb5dac hush: fix a case where return in sourced file has no effect
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-03-24 02:50:03 +01:00
Denys Vlasenko
bac0a25f72 slightly better wording in comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-02-21 03:47:50 +01:00
Denys Vlasenko
b12553faa8 ash: fix ash-signals/signal8 testcase failure
function                                             old     new   delta
killcmd                                              109     224    +115
kill_main                                            882     910     +28
changepath                                           194     195      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 144/0)             Total: 144 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-02-21 03:22:20 +01:00
Denys Vlasenko
8ee2adab21 echo: do not retry on write errors
function                                             old     new   delta
echo_main                                            297     336     +39
stpcpy                                                 -      22     +22
run_pipe                                            1561    1566      +5
pseudo_exec_argv                                     187     192      +5
hush_exit                                             75      80      +5
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 4/0 up/down: 98/0)               Total: 76 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-02-07 02:03:51 +01:00
Denys Vlasenko
7b4c0fd5f4 hush: fix improper handling of newline and hash chars in few corner cases
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-11-22 17:58:14 +01:00
Denys Vlasenko
6696eac274 hush: add support for "set -o pipefail"
function                                             old     new   delta
checkjobs                                            467     517     +50
builtin_set                                          259     286     +27
o_opt_strings                                          -      10     +10
hush_main                                           1011    1013      +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 89/0)               Total: 89 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-11-14 02:01:50 +01:00
Denys Vlasenko
2bcba5cc53 hush: add brace expansion testcase
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-10-03 17:07:57 +02:00
Denys Vlasenko
bed7c81ea2 shell/math: deconvolute and explain ?: handling. Give better error message
function                                             old     new   delta
arith_apply                                         1271    1283     +12

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-16 11:50:46 +02:00