#
c5aef537 |
| 16-Jun-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Reduce unnecessary forks with eval.
The eval special builtin now runs the code with EV_EXIT if it was run with EV_EXIT itself.
In particular, this eliminates one fork when a command substitutio
sh: Reduce unnecessary forks with eval.
The eval special builtin now runs the code with EV_EXIT if it was run with EV_EXIT itself.
In particular, this eliminates one fork when a command substitution contains an eval command that ends with an external program or a subshell.
This is similar to what r220978 did for functions.
show more ...
|
#
b8764e51 |
| 13-Jun-2011 |
Attilio Rao <attilio@FreeBSD.org> |
MFC
|
#
c543e1ae |
| 13-Jun-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Save/restore changed variables in optimized command substitution.
In optimized command substitution, save and restore any variables changed by expansions (${var=value} and $((var=assigned))), in
sh: Save/restore changed variables in optimized command substitution.
In optimized command substitution, save and restore any variables changed by expansions (${var=value} and $((var=assigned))), instead of trying to determine if an expansion may cause such changes.
If $! is referenced in optimized command substitution, do not cause jobs to be remembered longer.
This fixes $(jobs $!) again, simplifies the man page and shortens the code.
show more ...
|
#
8e3ed13f |
| 10-Jun-2011 |
Attilio Rao <attilio@FreeBSD.org> |
MFC
|
#
292e6676 |
| 10-Jun-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Do parameter expansion before printing PS4 (set -x).
The function name expandstr() and the general idea of doing this kind of expansion by treating the text as a here document without end marker
sh: Do parameter expansion before printing PS4 (set -x).
The function name expandstr() and the general idea of doing this kind of expansion by treating the text as a here document without end marker is from dash.
All variants of parameter expansion and arithmetic expansion also work (the latter is not required by POSIX but it does not take extra code and many other shells also allow it).
Command substitution is prevented because I think it causes too much code to be re-entered (for example creating an unbounded recursion of trace lines).
Unfortunately, our LINENO is somewhat crude, otherwise PS4='$LINENO+ ' would be quite useful.
show more ...
|
#
81c02539 |
| 06-Jun-2011 |
Attilio Rao <attilio@FreeBSD.org> |
MFC
|
#
b3f892d9 |
| 05-Jun-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Fix $? in heredocs on simple commands.
PR: bin/41410
|
#
3bce356e |
| 05-Jun-2011 |
Attilio Rao <attilio@FreeBSD.org> |
MFC
|
#
9338c85c |
| 04-Jun-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Honour -n while processing -c string.
|
#
87c3644c |
| 24-May-2011 |
Peter Grehan <grehan@FreeBSD.org> |
IFC @ r222256
|
#
8c4431d0 |
| 22-May-2011 |
Attilio Rao <attilio@FreeBSD.org> |
MFC
|
#
05a447d0 |
| 22-May-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Expand aliases after assignments and redirections.
|
#
7e7a34e5 |
| 16-May-2011 |
Attilio Rao <attilio@FreeBSD.org> |
MFC
|
#
e64a11e9 |
| 15-May-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Avoid close(-1) when evaluating a multi-command pipeline.
Valgrind complains about this.
|
#
03b3a844 |
| 25-Apr-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Set $? to 0 for background commands.
For backgrounded pipelines and subshells, the previous value of $? was being preserved, which is incorrect.
For backgrounded simple commands containing a co
sh: Set $? to 0 for background commands.
For backgrounded pipelines and subshells, the previous value of $? was being preserved, which is incorrect.
For backgrounded simple commands containing a command substitution, the status of the last command substitution was returned instead of 0.
If fork() fails, this is an error.
show more ...
|
#
45496405 |
| 24-Apr-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Allow EV_EXIT through function calls, make {...} <redir more consistent.
If EV_EXIT causes an exit, use the exception mechanism to unwind redirections and local variables. This way, if the final
sh: Allow EV_EXIT through function calls, make {...} <redir more consistent.
If EV_EXIT causes an exit, use the exception mechanism to unwind redirections and local variables. This way, if the final command is a redirected command, an EXIT trap now executes without the redirections.
Because of these changes, EV_EXIT can now be inherited by the body of a function, so do so. This means that a function no longer prevents a fork before an exec being skipped, such as in f() { head -1 /etc/passwd; }; echo $(f)
Wrapping a single builtin in a function may still cause an otherwise unnecessary fork with command substitution, however.
An exit command or -e failure still invokes the EXIT trap with the original redirections and local variables in place.
Note: this depends on SHELLPROC being gone. A SHELLPROC depended on keeping the redirections and local variables and only cleaning up the state to restore them.
show more ...
|
Revision tags: release/7.4.0_cvs, release/8.2.0_cvs, release/7.4.0, release/8.2.0 |
|
#
c059d822 |
| 05-Feb-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Remove clearcmdentry()'s now unused argument.
|
#
3835f47c |
| 04-Feb-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Remove special code for shell scripts without magic number.
These are called "shell procedures" in the source.
If execve() failed with [ENOEXEC], the shell would reinitialize itself and execute
sh: Remove special code for shell scripts without magic number.
These are called "shell procedures" in the source.
If execve() failed with [ENOEXEC], the shell would reinitialize itself and execute the program as a script. This requires a fair amount of code which is not frequently used (most scripts have a #! magic number). Therefore just execute a new instance of sh (_PATH_BSHELL) to run the script.
show more ...
|
#
e23a66ac |
| 06-Jan-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Do not call exitshell() from evalcommand() unless evalcommand() forked itself.
This ensures that certain traps caused by builtins are executed.
|
#
850460c0 |
| 01-Jan-2011 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Check readonly status for assignments on regular builtins.
An error message is written, the builtin is not executed, nonzero exit status is returned but the shell does not abort.
This was alrea
sh: Check readonly status for assignments on regular builtins.
An error message is written, the builtin is not executed, nonzero exit status is returned but the shell does not abort.
This was already checked for special builtins and external commands, with the same consequences except that the shell aborts for special builtins.
Obtained from: NetBSD
show more ...
|
#
11535bdf |
| 30-Dec-2010 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Avoid side effects from builtins in optimized command substitution.
Change the criterion for builtins to be safe to execute in the same process in optimized command substitution from a blacklist
sh: Avoid side effects from builtins in optimized command substitution.
Change the criterion for builtins to be safe to execute in the same process in optimized command substitution from a blacklist of only cd, . and eval to a whitelist.
This avoids clobbering the main shell environment such as by $(exit 4) and $(set -x).
The builtins jobid, jobs, times and trap can still show information not available in a child process; this is deliberately permitted. (Changing traps is not.)
For some builtins, whether they are safe depends on the arguments passed to them. Some of these are always considered unsafe to keep things simple; this only harms efficiency a little in the rare case they are used alone in a command substitution.
show more ...
|
#
acd7984f |
| 28-Dec-2010 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Don't do optimized command substitution if expansions have side effects.
Before considering to execute a command substitution in the same process, check if any of the expansions may have a side
sh: Don't do optimized command substitution if expansions have side effects.
Before considering to execute a command substitution in the same process, check if any of the expansions may have a side effect; if so, execute it in a new process just like happens if it is not a single simple command.
Although the check happens at run time, it is a static check that does not depend on current state. It is triggered by: - expanding $! (which may cause the job to be remembered) - ${var=value} default value assignment - assignment operators in arithmetic - parameter substitutions in arithmetic except ${#param}, $$, $# and $? - command substitutions in arithmetic
This means that $((v+1)) does not prevent optimized command substitution, whereas $(($v+1)) does, because $v might expand to something containing assignment operators.
Scripts should not depend on these exact details for correctness. It is also imaginable to have the shell fork if and when a side effect is encountered or to create a new temporary namespace for variables.
Due to the $! change, the construct $(jobs $!) no longer works. The value of $! should be stored in a variable outside command substitution first.
show more ...
|
#
45b71cd1 |
| 28-Dec-2010 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Make expansion errors in optimized command substitution non-fatal. Command substitutions consisting of a single simple command are executed in the main shell process but this should be invisible
sh: Make expansion errors in optimized command substitution non-fatal. Command substitutions consisting of a single simple command are executed in the main shell process but this should be invisible apart from performance and very few exceptions such as $(trap).
show more ...
|
#
1e7a698a |
| 25-Nov-2010 |
Dimitry Andric <dim@FreeBSD.org> |
Sync: merge r215709 through r215824 from ^/head.
|
#
9d37e157 |
| 23-Nov-2010 |
Jilles Tjoelker <jilles@FreeBSD.org> |
sh: Code size optimizations to "stack string" memory allocation: * Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC. * Add STPUTS macro (based on function) and use it instead of loop
sh: Code size optimizations to "stack string" memory allocation: * Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC. * Add STPUTS macro (based on function) and use it instead of loops that add nul-terminated strings to the stack string.
No functional change is intended, but code size is about 1K less on i386.
show more ...
|