aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
| * ash: implement "exec -a ARGV0 CMD ARGV1..."Denys Vlasenko2017-04-121-7/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * ash: make shellexec capable of using separate argv[0] and filename to execDenys Vlasenko2017-04-121-11/+10
| | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'busybox' into mergeRon Yorston2017-02-081-171/+294
|\|
| * ash: add INT_OFF/ON around allocationsDenys Vlasenko2017-02-031-2/+4
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: improve / fix glob expansionFelix Fietkau2017-01-311-17/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * *: add comment about APPLET_ODDNAME formatDenys Vlasenko2017-01-291-1/+2
| | | | | | | | | | | | It confused me more than once Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: commented-out possible fix for 7694Denys Vlasenko2017-01-111-4/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * ash: 16-bit ->nprocs field is a pain for many CPUsDenys Vlasenko2017-01-111-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * ash: split bash compatible extensions into separate defines. No code changesDenys Vlasenko2017-01-111-74/+101
| | | | | | | | | | | | | | | | 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>
| * ash: revert "make dot command search current directory first"Denys Vlasenko2017-01-101-9/+0
| | | | | | | | | | | | | | | | | | | | Reverts this: commit 8ad78e1ec7b2e873953f9f476fb63b5893526c39 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>
| * shells: make hush test optional, rename ASH_BUILTIN_foo -> ASH_fooDenys Vlasenko2017-01-101-13/+13
| | | | | | | | | | | | | | This makes hash and ash more symmetrical wrt config menu and config options. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * Big cleanup in config help and descriptionDenys Vlasenko2017-01-101-49/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * ash: fix a bug in argv restoration after sourcing a fileDenys Vlasenko2017-01-091-2/+4
| | | | | | | | | | | | if sourced file "shift"ed argvs so that $1 is NULL, restore wasn't done. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: make the noconsole option configurable at build timeRon Yorston2017-02-071-4/+20
| | | | | | | | | | | | | | | | | | The noconsole option depends on APIs that aren't available in all incarnations of Microsoft Windows. Allow it to be disabled at build time. Note that, by default, 'noconsole' is enabled in 32-bit builds but disabled in 64-bit builds.
* | Merge branch 'busybox' into mergeRon Yorston2017-01-081-4/+14
|\|
| * ash: fix open fds leaking in redirects. Closes 9561Denys Vlasenko2017-01-071-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | commit e19923f6652a638ac39c84012e97f52cf5a7568e 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>
| * ash: explicltly group ash optionsKang-Che Sung2017-01-061-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'busybox' into mergeRon Yorston2017-01-041-135/+158
|\|
| * ash: fix error code regressionRon Yorston2017-01-031-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * Make it possible to select "sh" and "bash" aliases without selecting ash or hushDenys Vlasenko2016-12-231-49/+46
| | | | | | | | | | | | | | 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>
| * shell: move "config" blocks above their use in coditional includesDenys Vlasenko2016-12-221-82/+81
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * Tweak some config defaults; fix MODPROBE_SMALL ordering in "make config"Denys Vlasenko2016-12-221-3/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: clarify uclibc glob() bug in commentDenys Vlasenko2016-12-211-0/+3
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: error out if ASH_INTERNAL_GLOB is not selected on uClibcDenys Vlasenko2016-12-211-0/+8
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix signed char expansion bugDenys Vlasenko2016-12-121-9/+21
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: suppress "unused var/func" warnings on some configsDenys Vlasenko2016-12-121-6/+6
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2016-11-291-3/+6
|\|
| * ash,hush: make ^C in interactive mode visually much closer to bash behaviorDenys Vlasenko2016-11-251-1/+3
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: ^C from command line should set $? to 128+SIGINTDenys Vlasenko2016-11-241-0/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * test: make [ and [[ forms individually selectableDenys Vlasenko2016-11-231-2/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2016-11-101-8/+26
|\|
| * ash: fix "duplicate local" code (forgot to re-enable interrupts)Denys Vlasenko2016-11-041-3/+20
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: while (!got_sig) pause() is not reliable, use sigsuspend()Denys Vlasenko2016-11-031-5/+6
| | | | | | | | | | | | | | dash was doing it for a reason. Unfortunately, it had no comment why... now I know. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Post-merge fixRon Yorston2016-11-021-1/+1
| |
* | Merge branch 'busybox' into mergeRon Yorston2016-11-021-41/+81
|\|
| * ash: if using libc glob(), skip it if no metachars are in wordDenys Vlasenko2016-10-301-0/+15
| | | | | | | | | | | | | | | | | | This saves making tons of pointless stat() calls function old new delta expandarg 888 921 +33 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix bit-rotten debug infrastructureDenys Vlasenko2016-10-301-14/+7
| | | | | | | | | | | | DEBUG = 2 output was a bit messed up Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: make popfile() anfter popallfiles() safeDenys Vlasenko2016-10-301-2/+5
| | | | | | | | | | | | | | | | | | | | | | In this example: ash -c 'readonly x; echo $(command eval x=2)' evalstring() is called after forkchild(), which calls popallfiles(). On exception, evalstring() will popfile(). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: use pause(), not sigsuspend(), in wait builtinDenys Vlasenko2016-10-281-26/+31
| | | | | | | | | | | | | | | | | | Same effect, smaller code function old new delta dowait 463 374 -89 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix interactive "command eval STRING" exiting on errors.Denys Vlasenko2016-10-281-1/+24
| | | | | | | | | | | | This bug is also present in current dash Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Post-merge fixesRon Yorston2016-10-281-3/+8
| | | | | | | | | | | | | | Signal handling has never really worked on WIN32 so: - don't bother compiling signal_handler() or setsignal(); - use waitpid_child() instead of new function wait_block_or_sig().
* | Merge branch 'busybox' into mergeRon Yorston2016-10-281-226/+241
|\|
| * ash: [JOBS] Fix dowait signal raceDenys Vlasenko2016-10-271-13/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Sun, 22 Feb 2009 18:10:01 +0800 [JOBS] Fix dowait signal race This test program by Alexey Gladkov can cause dash to enter an infinite loop in waitcmd. #!/bin/dash trap "echo TRAP" USR1 stub() { echo ">>> STUB $1" >&2 sleep $1 echo "<<< STUB $1" >&2 kill -USR1 $$ } stub 3 & stub 2 & until { echo "###"; wait; } do echo "*** $?" done The problem is that if we get a signal after the wait3 system call has returned but before we get to INTON in dowait, then we can jump back up to the top and lose the exit status. So if we then wait for the job that has just exited, then it'll stay there forever. I made the original change that caused this bug to fix pretty much the same bug but in the opposite direction. That is, if we get a signal after we enter wait3 but before we hit the kernel then it too can cause the wait to go on forever (assuming the child doesn't exit). In fact this is pretty much exactly the scenario that you'll find in glibc's documentation on pause(). The solution is given there too, in the form of sigsuspend, which is the only way to do the check and wait atomically. So this patch fixes Alexey's race without reintroducing the old bug by converting the blocking wait3 to a sigsuspend. In order to do this we need to set a signal handler for SIGCHLD, so the code has been modified to always do that. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> I failed to reproduce the bug (it requires precise timing), but it seems real. function old new delta dowait 284 463 +179 setsignal 301 326 +25 signal_handler 59 76 +17 ash_main 1481 1487 +6 localcmd 350 348 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 227/-2) Total: 225 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: [SIGNAL] Remove EXSIGDenys Vlasenko2016-10-271-64/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit 1: Date: Sun, 22 Feb 2009 18:16:13 +0800 [SIGNAL] Remove EXSIG Now that waitcmd no longer uses EXSIG we can remove it. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Upstream commit 2: Date: Thu, 2 Oct 2014 21:07:55 +0800 [ERROR] Set exitstatus in onint Currently the exit status when we receive SIGINT is set in evalcommand which means that it doesn't always get set. For example, if you press CTRL-C at the prompt of an interactive dash, the exit status is not set to 130 as it is in many other Bourne shells. This patch fixes this by moving the setting of the exit status into onint which also simplifies evalcommand. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Upstream commit 3: Date: Fri, 3 Oct 2014 14:07:07 +0800 [EVAL] Do not clobber exitstatus in evalcommand All originators of EXERROR have been setting the exitstatus for a while now. So it is no longer appropriate to set it explicitly in evalcommand. In fact doing so may cause the original exitstatus to be lost. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Last three coomits: function old new delta waitcmd 186 224 +38 dowait 276 284 +8 waitforjob 104 107 +3 localcmd 348 350 +2 showjobs 64 61 -3 forkshell 263 260 -3 raise_interrupt 93 67 -26 blocking_wait_with_raise_on_sig 40 - -40 evalcommand 1264 1208 -56 evaltree 809 498 -311 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: open-code blocking_dowait_with_raise_on_sig()Denys Vlasenko2016-10-271-18/+7
| | | | | | | | | | | | There is in fact only one callsite. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: return to DOWAIT_* constants similar to dash, no logic changesDenys Vlasenko2016-10-271-11/+16
| | | | | | | | | | | | | | This loses an insignificant optimization, but may allow backporting of some recent-ish dash fixes. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: delete leftovers from "simplify EOF/newline handling in list parser" commitDenys Vlasenko2016-10-271-4/+0
| | | | | | | | | | | | | | | | | | | | | | This commit should have deleted these two statements: commit c0e007663d30f83b0e5e074db34dcffaa8915e99 Author: Ron Yorston <rmy@pobox.com> Date: Thu Oct 29 11:30:55 2015 +0000 ash: simplify EOF/newline handling in list parser Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: [EXPAND] Fix ifsfirst/ifslastp leakDenys Vlasenko2016-10-271-9/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Wed, 8 Sep 2010 20:07:26 +0800 [EXPAND] Fix ifsfirst/ifslastp leak As it stands expandarg may return with a non-NULL ifslastp which then confuses any subsequent ifsbreakup user that doesn't clear it directly. What's worse, if we get interrupted before we hit ifsfree in expandarg we will leak memory. This patch fixes this by always calling ifsfree in expandarg thus ensuring that ifslastp is always NULL on the normal path. It also adds an ifsfree call to the RESET path to ensure that memory isn't leaked. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Fallout 1: Date: Mon, 18 Oct 2010 10:55:42 +0800 [EXPAND] Fix ifsfirst/ifslastp leak in casematch The commit f42e443bb511ed3224f09b4fcf0772438ebdbbfa [EXPAND] Fix ifsfirst/ifslastp leak revealed yet another ifsfirst/ifslastp leak in casematch. Previously it was hidden because ifsfirst/ifslastp was cleared unconditionally on entry (which caused the leakage of those entries). Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Fallout 2: Date: Sun, 28 Nov 2010 21:09:51 +0800 [EXPAND] Free IFS state in evalbackcmd On Sun, Nov 07, 2010 at 04:04:20PM -0600, Jonathan Nieder wrote: > Herbert Xu wrote: > > commit f42e443bb511ed3224f09b4fcf0772438ebdbbfa > > Author: Herbert Xu <herbert@gondor.apana.org.au> > > Date: Wed Sep 8 20:07:26 2010 +0800 > > > > [EXPAND] Fix ifsfirst/ifslastp leak > > Another puzzle bisecting to f42e443bb. This one comes from the > grub-mkconfig script: > > $ sh -c 'datadir=/usr/share; pkgdatadir=${datadir}/`cat`' 2>&1 | cat -A > cat: M-^\^M^F^HM-4^M^F^HM-(^M^F^H: No such file or directory$ > cat: M-(^M^F^H: No such file or directory$ > > Still reproducible with 016b529. I'll try to find time to look into > it, but thought you might like to know nevertheless. This is the symptom of another leak. In this case evalbackcmd occurs in the middle of an expansion (as it should) but the forked child never clears the previous IFS state. This patch adds the missing ifsfree call. This wasn't as much of a problem as the previously discovered leaks since all it means is that the child gets to carry around the parent's expansion state and the child is usually short-lived. Reported-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Fallout 3: Date: Tue, 15 Mar 2011 16:01:34 +0800 [EXPAND] Free IFS state after here document expansion Here's another bug bisecting to f42e443bb ([EXPAND] Fix ifsfirst/ifslastp leak, 2010-09-08). It was found with the following test case, based on the configure script for Tracker: dash -x -c ' <<-_ACEOF $@ _ACEOF exec ' - abcdefgh + + exec ?a exec: 1: : Permission denied The missing ifsfree call is in expandarg when it returns to openhere during here document expansion. Reported-by: Aurelien Jarno <aurel32@debian.org> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta ifsfree - 66 +66 ash_main 1490 1495 +5 argstr 1154 1159 +5 evalcase 275 270 -5 expandarg 972 888 -84 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/2 up/down: 76/-89) Total: -13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: move ifsbreakup() and ifsfree() upDenys Vlasenko2016-10-271-110/+110
| | | | | | | | | | | | Preparatory patch. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: partially sync with dash on "fork if traps are set" logicDenys Vlasenko2016-10-271-5/+6
| | | | | | | | | | | | | | | | Upstream commit "[EVAL] Force fork if any trap is set, not just on EXIT" had a similar code as our fix to that bug. Eliminate some superficial differences. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>