summary refs log tree commit diff
Commit message (Collapse)AuthorAge
...
* Release 0.5.7.Herbert Xu2011-07-08
|
* [EVAL] Avoid using undefined handlerJim Meyering2011-07-08
| | | | | | | | | | * src/eval.c (evalbltin, evalfun): Set savehandler before calling setjmp with the possible "goto *done", where savehandler is used. Otherwise, clang warns that "Assigned value is garbage or undefined" at the point where "savehandler" is used on the RHS. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [MEMALLOC] Avoid clang warning about dead store to "size"Jim Meyering2011-07-08
| | | | | | | * src/memalloc.c (makestrspace): Remove dead store. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [MEMALLOC] Avoid gcc warning: variable 'oldstackp' set but not usedJim Meyering2011-07-08
| | | | | | | | * src/memalloc.c (growstackblock): Remove declaration and set of set-but-not-used variable. Also remove a stray space-before-TAB. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Eliminate unnecessary promotion in echocmdHerbert Xu2011-07-07
| | | | | | | | The patch to make outc into an inline function created an unnecessary promotion in echocmd due to its use of char vs. the int used by outc. This patch changes echocmd to use int instead. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [OUTPUT] Make outc an inline functionJonathan Nieder2011-07-07
| | | | | | | | | | | | | As "gcc -pedantic" warns, ISO C forbids conditional expressions with only one void side. So the (needslow ? slowpath() : fastpath) code for outc in the !USE_GLIBC_STDIO case might not be portable. More importantly, it's hard to read. Rip it out and replace it with an inline function which should generate the same code. Reported-by: Szabolcs Nagy <nsz@port70.net> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [MAN] Remove spurious space in descriptions of PS1, PS2, PS4Kalle Olavi Niemitalo2011-07-07
| | | | | | | | | | | | | | | | | | | | | From: Kalle Olavi Niemitalo <kon@iki.fi> LANG=C man dash shows: PS1 The primary prompt string, which defaults to ``$ '', unless you are the superuser, in which case it defaults to ``# ''. PS2 The secondary prompt string, which defaults to ``> ''. PS4 Output before each line when execution trace (set -x) is enabled, defaults to ``+ ''. Each of the documented default values has a graphic character and two spaces between the quotation marks. However, the actual default values have only one space, rather than two. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Optimize dash -c "command" to avoid a forkHerbert Xu2011-07-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* [EVAL] Remove unused EV_BACKCMD flagJonathan Nieder2011-07-07
| | | | | | | | | | | | | | | | | | | | | The original ash defered forking commands in backquotes so builtins could be run in the same context as the shell. This behavior was controlled using the EV_BACKCMD to evaltree. Unfortunately, as Matthias Scheler noticed in 1999 (NetBSD PR/7814), the result was counterintuitive; for example, echo "`cd /`" would change the cwd. So ash 0.3.5 left out that optimization. The EV_BACKCMD codepath stayed around, unused. Some time between ash 0.3.5-11 and ash 0.3.8-37, Debian ash omitted the EV_BACKCMD pathway by guarding it with #ifdef notyet. In dash 0.5.1 and later, the commented code is no more. Let's finish the job and remove the last vestiges. If someone wants to work on omitting the fork in backcmd, the remaining hints are not going to be very helpful, anyway. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [PARSER] Fix clobbering of checkkwdHerbert Xu2011-03-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Sun, Nov 07, 2010 at 02:21:21AM +0000, Jonathan Nieder wrote: > > Just ran into some strange behavior: > > $ cat test.sh > #!/bin/sh > echo hello >greeting > cat <<EOF && > $(cat greeting) > EOF > { > echo $? > cat greeting > } >/dev/null > > > $ sh test.sh > hello > test.sh: 7: {: not found > 127 > hello > test.sh: 10: Syntax error: "}" unexpected > > bash, mksh, pdksh, and ksh93 all print hello as expected. The problem > is reproducible with all versions of dash in the git repo. This is caused by the clobbering of checkkwd due to readtoken recursion while parsing a here document. This patch fixes it by saving the original value of checkkwd. Reported-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [DEBUG] Use va_copy when reusing a va_listJonathan Nieder2011-03-15
| | | | | | | | | | | | | | | | | When tracing (with the DEBUG compile-time option set to 1 or 2), exverror calls TRACEV to print its arguments before passing them on. So the arguments are consumed by the time exvwarning looks for them, resulting in a segfault: $ sh -c '"' sh: Syntax error: Unterminated quoted string $ sh -o debug -c '"' sh: Segmentation fault (core dumped) Make a copy with va_copy to avoid this. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Free IFS state after here document expansionJonathan Nieder2011-03-15
| | | | | | | | | | | | | | | | | | | | | | | 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>
* [SHELL] Improve LINENO supportHarald van Dijk2011-03-15
| | | | | | | | | | | | This patch improves LINENO support by storing line numbers in the parse tree, for commands as well as for function definitions. It makes LINENO behaves properly when calling functions, and has the added benefit of improved line numbers in error messages when the last-parsed command is not the last-executed one. It removes the earlier LINENO support, and instead sets LINENO from evaltree when a command is executed Signed-off-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EVAL] Let funcnode refer to a function definition, not its first commandHarald van Dijk2011-03-15
| | | | | | | | | | | | It is not unrelated: I changed the meaning of struct funcnode's field n to refer to the function definition, rather than the list of the function's commands, because I needed to refer to the function definition node from evalfun, which only gets passed a funcnode. But it is something that could be applied independently (without being useful by itself), so I've attached it as a separate patch for easier review. Signed-off-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Port to SolarisBrian Koropoff2011-03-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Solaris lacks paths.h and the various _PATH_* #defines. Check for them in configure.ac and fall back on the usual suspects when they are missing. - Older Solaris lacks isblank(), and versions that have it use a macro. Check for the declaration in configure.ac and fall back on a naive version when missing. - Older Solaris does not support %jd (intmax_t) in format strings, but it does support the PRIdMAX macro from inttypes.h. Do a configure check for PRIdMAX and use it in the code. If it doesn't exist, define it to "lld" when sizeof(long long) equals sizeof(intmax_t) as this is more likely to work on older systems. Otherwise, use "jd" and hope for the best. - Older Solaris lacks stdint.h, but inttypes.h provides the same types and works on all platforms I've tried dash on, so just use it instead. - Older Solaris doesn't like it when vsnprintf() is passed a NULL buffer (in violation of the POSIX spec, of course). Pass a 1-byte dummy buffer instead. - Solaris lacks tempfile and mktemp programs. Fall back on a "good-enough" custom function in mkbuiltins. Signed-off-by: Brian Koropoff <bkoropoff@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Fix backslash handling in read(1)Herbert Xu2011-03-11
| | | | | | | | | | | | The new read(1) implementation incorrectly assumes that ifsbreakup ignores characters escaped by CTLESC. As such it fails to handle backslashes except for escaping newlines. This patch makes it use recordregion for every part that isn't escaped by a backslash. Reported-by: Jilles Tjoelker <jilles@stack.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Dotcmd should exit with zero when doing nothingJonathan Nieder2011-03-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | Tim Allen wrote: > The POSIX specification for the dot command[1] states: > > EXIT STATUS > Returns the value of the last command executed, or a zero exit > status if no command is executed. > > If an empty file is sourced, then "no command is executed" I agree. Looking through "git log --patch src/main.c", though, I find v0.5.3~42 (Do not clobber exit status in dotcmd., 2005-03-03), which appears to have been meant to take care of the following case: $ cat printstatus.sh echo $? $ false $ . ./printstatus.sh 1 I wonder if the following on top might help (imitating evalcmd)? Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Fix CTLESC clobbering by read(1)Herbert Xu2011-03-10
| | | | | | | | | | | | | The changeset 55c46b7286f5d9f2d8291158203e2b61d2494420 [BUILTIN] Honor tab as IFS whitespace when splitting fields in readcmd uses CTLESC to prevent field splitting in read(1). However, it did not escape CTLESC itself in the input stream. This patch adds the necessary CTLESC characters so that CTLESC isn't corrupted. Reported-by: Alexey Gladkov <gladkov.alexey@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Port to AIXBrian Koropoff2011-03-10
| | | | | | | | | | | | | | - AIX lacks a WCOREDUMP macro. It's just used to append "(core dumped)" to the crash message, so #ifdef around it. - For some reason, the nl program on AIX defaults to not printing line numbers ("-b n"), even though the spec says it should default to "-b t". Explicitly pass "-b a" for good measure in mkbuiltins. Signed-off-by: Brian Koropoff <bkoropoff@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Do not split the result of tilde expansionJilles Tjoelker2011-03-10
| | | | | | | | | | | | | | | A tilde expansion generates a valid pathname. Splitting it using IFS either leaves it unchanged or changes it to something unintended. This fixes FreeBSD sh test expansion/tilde1.0 and does not change the outcome of the other tests. This fixes Debian bug #601096. Example: IFS=m HOME=/tmp; printf "%s\n" ~ Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [REDIR] Replace GPL noclobberopen code with the FreeBSD versionJilles Tjoelker2011-03-10
| | | | | | | | | 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>
* [EXPAND] Free IFS state in evalbackcmdHerbert Xu2010-11-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* [SIGNAL] Mark status as volatile in exitshellMaciej Żenczykowski2010-11-28
| | | | | | | | trap.c: In function 'exitshell': trap.c:354: warning: variable 'status' might be clobbered by 'longjmp' or 'vfork' Signed-off-by: Maciej Żenczykowski <zenczykowski@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Stop documenting EXSHELLPROCJonathan Nieder2010-11-28
| | | | | | | | | | | At some point between ash 0.3.5-11.0.1 and ash 0.3.8-37, Debian ash stopped using the EXSHELLPROC exception to handle shell scripts without a magic number. Remove all remaining references to it to avoid confusion. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Use EXEXIT in place of EXEXECJonathan Nieder2010-11-28
| | | | | | | | | | | | | | | | | | | | | | The intended semantics of EXEXEC are identical to EXEXIT, so simplify by using EXEXIT directly. Functional change: in edge cases (exec within a trap handler), this causes the exit status from exec not to be clobbered. For example, without this patch: $ sh -c 'trap "exec nonexistent" EXIT'; echo $? exec: 1: nonexistent: not found 0 And with it: $ sh -c 'trap "exec nonexistent" EXIT'; echo $? exec: 1: nonexistent: not found 127 Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [INPUT] Use exit status 127 when the script to run does not existGerrit Pape2010-11-28
| | | | | | | | | | | | | | This commit makes dash exit with return code 127 instead of 2 if started as non-interactive shell with a non-existent command_file specified as argument (or a directory), as documented in http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html#tag_04_128_14 The wrong exit code was reported by Clint Adams and Jari Aalto through http://bugs.debian.org/548743 http://bugs.debian.org/548687 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [ERROR] Allow the originator of EXERROR to set the exit statusHerbert Xu2010-11-28
| | | | | | | | Some errors have exit status values specified by POSIX and it is therefore desirable to be able to set the exit status at the EXERROR source rather than in main.c. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [MAN] Document optional open parenthesis for case patternsPhilipp Weis2010-11-28
| | | | | | | | | | While inspecting some dash scripts on my system, I was surprised to see that some of them use an open parenthesis at the beginning of case patterns while that's not mentioned in the manpage. Dash currently is fine with and without that parenthesis (parser.c:413). The attached patch documents this feature. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EVAL] Fixed trap/return regression due to SKIPEVAL removalHerbert Xu2010-11-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Wed, Aug 11, 2010 at 08:06:16AM +0000, Guido Berhoerster wrote: > > with the latest git version of dash trap actions are not > evaluated in the context of a function. > > The following script demonstrates the bug: > ----8<---- > read_timeout () { > saved_traps="$(trap)" > trap 'printf "timed out\n"; eval "${saved_traps}"; return' TERM > ( sleep $1; kill -TERM $$ ) >/dev/null 2>&1 & > timer_pid=$! > read $2 > kill $timer_pid 2>/dev/null > } > > read_timeout 5 value > printf "read \"%s\"\n" "${value:=default}" > > ---->8---- > The return statement in the trap inside the read_timeout function > does not return from the function but rather exits the script. > > With dash 0.5.5.1 it works as expected. This bug was caused by the SKIPEVAL removal. When the SKIPEVAL hack was added to improve set -e support in traps, dotrap was changed to return whether set -e was detected. After the removal of SKIPEVAL, set -e is now handled through exraise. However, dotrap still returned a value which is now incorrectly used to trigger an exraise. This patch removes the vestigial link between dotrap and exraise. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Fix ifsfirst/ifslastp leak in casematchHerbert Xu2010-10-18
| | | | | | | | | | | | | 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>
* [BUILTIN] Fix EXEXEC status clobberingHerbert Xu2010-10-07
| | | | | | | | | | | evalcommand always clobbers the exit status in case of an EXEXEC which means that exec always fails with exit status 2 regardless of what it actually returns. This patch adds the missing check for EXEXEC so that the correct exit status is preserved. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Fix trailing field bug in read(1)Herbert Xu2010-09-08
| | | | | | | | | | The new read(1) code fails to handle the last variable correctly if it happens to be terminated by IFS characters. Those characters are included in the last variable but they should not be. This patch fixes this. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Fix ifsfirst/ifslastp leakHerbert Xu2010-09-08
| | | | | | | | | | | | | | | | 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>
* [JOBS] Debug compile fixmaximilian attems2010-09-08
| | | | | | | | | | | No point in tracing a no longer undeclared "ps->cmd", fixes: jobs.c: In function \u2018commandtext\u2019: jobs.c:1192: error: \u2018ps\u2019 undeclared (first use in this function) jobs.c:1192: error: (Each undeclared identifier is reported only once jobs.c:1192: error: for each function it appears in.) Signed-off-by: maximilian attems <max@stro.at> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [VAR] Fix varinit ordering that broke fcJilles Tjoelker2010-09-08
| | | | | | | | | | | | | | | Git commit 0df96793ef6aa103df228d7dfe56099b7d721a15 "[SHELL] Add preliminary LINENO support" added the LINENO variable in the middle of other initialized variables, causing some macros for TERM and HISTSIZE to break (both of these are only used if libedit support is compiled in, which is not the case by default). The breakage is the same as can be seen by setting HISTSIZE=0. Also add a comment warning about this. Reported-by: Wez Furlong <kingwez@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EVAL] Check exit for eval NSUBSHELLGerrit Pape2010-07-06
| | | | | | | | | | | | | | | Example: $ dash -c 'set -e; (false); echo here' here With this commit, dash exits 1 before echo. The bug was reported by Stefan Fritsch through http://bugs.debian.org/514863 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EVAL] Removed dead code for eval NPIPEHerbert Xu2010-07-06
| | | | | | The notyet code is identical to the current code. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [VAR] Fix loss of variables when hash collidesHerbert Xu2010-07-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* [EVAL] Don't clear eflag in evalbackcmdGerrit Pape2010-06-28
| | | | | | | | | | | | | | | | | | | | | | According to http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_12 "A subshell environment shall be created as a duplicate of the shell environment, except that signal traps set by that shell environment shall be set to the default values." Currently the eflag is cleared when forking a subshell, e.g. $ dash -c 'set -e ; z=$(false;echo foo) ; echo $z' foo With this commit the eflag is preserved for subshells, and dash exits 1 before echo. The problem was reported by Vincent Lefevre through http://bugs.debian.org/514863 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Continue after EINTR in read(1) with no pending signalsHerbert Xu2010-05-29
| | | | | | | | | | | | The recent introduction of SIGCHLD trapping broke read(1) as each SIGCHLD may cause read(1) to return prematurely. Now if we did have a trap for SIGCHLD read(1) should actually do this. However, returning when SIGCHLD isn't trapped is wrong. This patch fixes this by checking for EINTR and pendingsigs in read(1). Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [JOBS] Fix wait regression where it does not wait for all jobsHerbert Xu2010-05-27
| | | | | | | | | | | The sigsuspend patch broke wait by making it return after just one job has completed. This is because we rely on pendingsigs to signal work and never clear it until waitcmd finishes. This patch adds a separate gotsigchld for this purpose so we can clear it before we start waiting. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Fix corruption of redirections with byte 0x81Jilles Tjoelker2010-05-27
| | | | | | | | | | | | | | | | | | 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>
* [EVAL] Force fork if any trap is set, not just on EXITJilles Tjoelker2010-05-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | In some cases the shell executes a subshell or an external command in the current process. This is not done if a trap on EXIT has been set, so that that trap can execute after the subshell or external command has finished. Extend that check to all traps. (A trap is "set" if a non-empty command string has been attached to it.) Improve encapsulation by exporting an accessor function for this and making the trap array static again. This is much like FreeBSD SVN r194127, enhanced to apply to subshells also (see FreeBSD SVN r194774). Example: dash -c '{ trap "echo moo" TERM; sleep 3; }& sleep 1; kill $!;wait' This should print "moo" after 3 seconds. Example: dash -c '{ trap "echo moo" TERM; (sleep 3) }& sleep 1; kill $!;wait' The same. Example: dash -c '{ trap "echo moo" TERM; sleep 3; :; }& sleep 1; kill $!;wait' This works correctly even without this patch. Signed-off-by: Jilles Tjoelker <jilles@stack.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [REDIR] Fix popredir on abnormal exit from built-inHerbert Xu2010-05-27
| | | | | | | | | 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>
* [REDIR] Move null redirect checks into callerHerbert Xu2010-05-27
| | | | | | | | | The null redirect checks were added as an optimisation to avoid unnecessary memory allocations. However, we could avoid this completely by simply making the caller avoid making a redirection unless it is not null. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [VAR] Do not poplocalvars prematurely on regular utilitiesHerbert Xu2010-05-27
| | | | | | | | | | | 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>
* [VAR] Document local command behaviour changeHerbert Xu2010-05-27
| | | | | | | | The localvar nesting changeset causes local to fail when used outside functions. While this behaviour is consistent with other shells, it is a change in dash's beavhiour. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [VAR] Fix poplocalvar on abnormal exit from functionHerbert Xu2010-05-27
| | | | | | | | | | 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>
* [VAR] Replace cmdenviron with localvarsHerbert Xu2010-05-26
| | | | | | | | | | 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>
* [VAR] Move unsetvar functionality into setvareqHerbert Xu2010-05-26
| | | | | | | | 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>