summary refs log tree commit diff
path: root/src/main.c (follow)
Commit message (Collapse)AuthorAge
* [BUILTIN] Return without arguments in a trap should use status outside trapsHerbert Xu2014-10-06
| | | | | | | | | | | | | POSIX now requires that return without arguments in a trap should return the last command status prior to executing traps. This patch implements this behaviour. Incidentally this also changes the behaviour of return without arguments in a loop conditional to use the last exit status in the body as opposed to the last command in the conditional when there is one. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Exit without arguments in a trap should use status outside trapsHerbert Xu2014-10-06
| | | | | | | | POSIX now requires that exit without arguments in a trap should return the last command status prior to executing traps. This patch implements this behaviour. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Merge SKIPFUNC/SKIPFILE and only clear SKIPFUNC when leaving dotcmdHerbert Xu2011-07-09
| | | | | | | | | | | | | | | | Currently upon leaving a dotcmd the evalskip state is reset so if a continue/break statement is used within a dot script it would have no effect outside of the dot script. This is inconsistent with other shells. This patch is based on one by Jilles Tjoelker and only clears SKIPFUNC when leaving a dot script. As a result continue/break will remain in effect. It also merges SKIPFUNC/SKIPFILE as they have no practical difference. 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>
* [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>
* [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>
* [EVAL] Revert SKIPEVAL into EXEXITHerbert Xu2009-08-11
| | | | | | | Now that eval handles EV_TESTED correctly, we can remove the SKIPEVAL hack and simply use EXEXIT for set -e. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [OPTIONS] Added support for -lHerbert Xu2008-07-13
| | | | | | | This patch adds support for the -l option (login shell) as required by the LSB. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Expand ENV before using itHerbert Xu2008-07-13
| | | | | | Per POSIX ENV needs to undergo parameter expansion. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* Copyright/licence updates and remove all traces of sys/cdefs.hHerbert Xu2005-10-29
| | | | | | | | | | | This change updates the BSD licence to the three-clause version since NetBSD has already done so. This makes dash GPL-compatible. It also adds Christos Zoulas (NetBSD ash maintainer) to the COPYING file. I've added "copyright by Herbert Xu" to most files. Finally all CVS IDs and inclusion of sys/cdefs.h have been removed. The latter is needed for support of klibc.
* Added eflag fixes for trap and minusc.herbert2005-09-26
| | | | | | Let evaltree handle traps from cmdloop. Reset evalskip after minusc is executed. Stop executing traps once SKIPEVAL is seen.
* Let evaltree handle traps from cmdloop.herbert2005-09-26
|
* Handle SKIPEVAL in read_profile by exiting.herbert2005-09-26
|
* Generalise setinputfile for use in read_profile/readcmdfile.herbert2005-09-26
|
* Do not clobber exit status in dotcmd.herbert2005-09-26
|
* Removed redundant setstackmark from dotcmd.herbert2005-09-26
|
* Removed qflag.herbert2005-09-26
|
* Renamed error to sh_error.herbert2005-09-26
|
* Replaced EXEVAL with SKIPEVAL.herbert2005-09-26
|
* Optimise away status and case statement in main().herbert2005-09-26
|
* Eliminated global exerrno.herbert2005-09-26
|
* Size optimisations with state/s in main().herbert2005-09-26
|
* Catch set -e exits within built-in commands.herbert2005-09-26
|
* Changed boolean rootshell into shlvl counter.herbert2005-09-26
|
* Initial import.Herbert Xu2005-09-26