Commit Graph

1923 Commits

Author SHA1 Message Date
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
Denys Vlasenko
4e4f88e569 hush: global_args_malloced is used only if set builtin is enabled
function                                             old     new   delta
run_pipe                                            1623    1635     +12
builtin_source                                       210     222     +12
save_and_replace_G_args                               70      60     -10
builtin_shift                                        132      94     -38
restore_G_args                                        98       -     -98
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/2 up/down: 24/-146)          Total: -122 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 07:57:38 +01:00
Denys Vlasenko
cc2fd5a986 hush: fix 'defined but not used' warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 06:19:55 +01:00
Denys Vlasenko
5362cc4b8c hush: remove redundand test for ENABLE_HUSH_JOB
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 05:57:13 +01:00
Denys Vlasenko
fd68f1e80d hush: fix kill builtin without jobs support
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 05:47:57 +01:00
Denys Vlasenko
442a414d66 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 05:11:09 +01:00
Denys Vlasenko
41ade05cac hush: conditionalize print_escaped() on EXPORT || TRAP
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:56:24 +01:00
Denys Vlasenko
4471969db2 hush: make memleak builtin optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:44:41 +01:00
Denys Vlasenko
6ec76d8719 hush: make export builtin optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:40:41 +01:00
Denys Vlasenko
d5933b1125 hush: make umask builtin optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:31:39 +01:00
Denys Vlasenko
10d5ece64a hush: make set/unset builtins optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:28:43 +01:00
Denys Vlasenko
7a85c60e7e hush: make read and trap builtins optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 17:40:18 +01:00
Denys Vlasenko
1125d7d680 hush: kill builtin and kill %jobspec support
Also made it and printf, type and wait builtins optional.

function                                             old     new   delta
builtin_kill                                           -     323    +323
bltins1                                              336     348     +12
builtin_type                                         114     116      +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 337/0)             Total: 337 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 17:19:38 +01:00
Denys Vlasenko
d5b5c2fa15 hush: support %%, %+ and % jobspec (meaning "current job")
function                                             old     new   delta
parse_jobspec                                         83     133     +50
builtin_wait                                         278     283      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 15:46:04 +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
Kang-Che Sung
6cd0294725 ash: explicltly group ash options
This would makes all ash options indented inside "ash" in menuconfig.
It appears that menuconfig has a limit at tracking multiple dependency
lines like this (it looks like a "diamond problem" but I'm not sure if
it is):

               ---ASH <----------
              /                  \       ASH_OPTIMIZE_FOR_SIZE
    !NOMMU <-*----SH_IS_ASH <----[OR] <--ASH_INTERNAL_GLOB
              \                  /       ASH_RANDOM_SUPPORT
               ---BASH_IS_ASH <--        [...]

The kconfig-language document [1] states that:

> If a menu entry somehow depends on the previous entry, it can be
> made a submenu of it. First, the previous (parent) symbol must be
> part of the dependency list and then one of these two conditions
> must be true:
> - the child entry must become invisible, if the parent is set to 'n'

    [BusyBox ash used to satisfy this, but no longer does]

> - the child entry must only be visible, if the parent is visible

    [BusyBox ash configs actually satisfy this, but because of
     "diamond" above this might not be easily detected]

So I found out a direct workaround: by making ash options explicitly
depend on !NOMMU, we can tell menuconfig that rule 2 above is satisfied
without any more tracking.

               ---------------------
              /                     \
    !NOMMU <-*-----ASH <--------     \
              \                 \     \        ASH_OPTIMIZE_FOR_SIZE
               *---SH_IS_ASH <---[OR]-[AND] <--ASH_INTERNAL_GLOB
                \                /             ASH_RANDOM_SUPPORT
                 --BASH_IS_ASH <-              [...]

So all ash options would now be indented under "ash".

[1] "Documentation/kbuild/kconfig-language.txt" in Linux kernel source

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-06 17:03:18 +01:00
Kang-Che Sung
9529115c4c shell: clarify help text of CONFIG_{SH,BASH}_IS_* options
Mention the behavior if user selects CONFIG_SH_IS_ASH but not
CONFIG_ASH. We will be explicit that invocations like "busybox ash"
will not work for such configuration.

Also clarify help text of CONFIG_BASH_IS_* that bash compatibility in
ash is not complete. (It shouldn't be anyway - ash can't support every
bash quirk out there.)

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-04 12:29:04 +01:00
Denys Vlasenko
b05bcaf29c hush: correct exitcode for unterminated ')' - exitcode2.tests testcase
function                                             old     new   delta
parse_stream                                        2595    2609     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-03 11:47:50 +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
0b8835861b Make it possible to select "sh" and "bash" aliases without selecting ash or hush
The same can be done for msh, but we are probably better off just deleting it
in a next versio or two.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 16:56:43 +01:00
Denys Vlasenko
6704746c69 shell: move "config" blocks above their use in coditional includes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-22 15:21:58 +01:00
Denys Vlasenko
326edc3e37 Tweak some config defaults; fix MODPROBE_SMALL ordering in "make config"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-22 14:36:49 +01:00
Denys Vlasenko
2166952ec3 ash: clarify uclibc glob() bug in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-21 21:04:16 +01:00
Denys Vlasenko
3a4cdf45f9 ash: error out if ASH_INTERNAL_GLOB is not selected on uClibc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-21 04:13:23 +01:00
Denys Vlasenko
2fe66b1d2d ash: fix signed char expansion bug
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 17:39:12 +01:00
Denys Vlasenko
b6afcc7819 shell: suppress "unused var/func" warnings on some configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 16:30:20 +01:00
Denys Vlasenko
4b89d512b1 ash,hush: make ^C in interactive mode visually much closer to bash behavior
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-25 03:41:03 +01:00
Denys Vlasenko
8660aeb312 ash,hush: ^C from command line should set $? to 128+SIGINT
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-24 17:44:02 +01:00
Denys Vlasenko
15fb91cefb test: make [ and [[ forms individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 18:31:48 +01:00
Denys Vlasenko
87e039d016 hush: make getch/peek functions directly called
Indirect calls are more difficult to predict.
Unfortunately, on x64 direct call is 5 bytes while indirect "call (reg+ofs)"
is 3 bytes:

function                                             old     new   delta
i_getch                                                -      82     +82
i_peek                                                 -      63     +63
parse_stream                                        2531    2579     +48
parse_dollar                                         771     797     +26
parse_redirect                                       296     321     +25
add_till_closing_bracket                             408     420     +12
encode_string                                        256     265      +9
i_peek_and_eat_bkslash_nl                             93      99      +6
add_till_backquote                                   110     114      +4
parse_and_run_stream                                 139     141      +2
expand_vars_to_list                                 1143    1144      +1
static_peek                                            6       -      -6
setup_string_in_str                                   39      18     -21
setup_file_in_str                                     40      19     -21
static_get                                            27       -     -27
file_peek                                             52       -     -52
file_get                                              65       -     -65
------------------------------------------------------------------------------
(add/remove: 2/4 grow/shrink: 9/2 up/down: 278/-192)           Total: 86 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 22:35:05 +01:00
Denys Vlasenko
00a06b9715 hush: renumber PIPE_foo, make PIPE_SEQ = 0
PIPE_SEQ is used most often, having it zero makes code smaller:

function                                             old     new   delta
done_word                                            719     707     -12
parse_stream                                        2546    2531     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 20:35:53 +01:00
Denys Vlasenko
6c635d62d4 hush: small optimization in run_list
I thought gcc can detect this itself. It doesn't.

function                                             old     new   delta
run_list                                            1030    1021      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 20:26:11 +01:00