| #
e8999de4 |
| 09-Feb-2019 |
kre <kre@NetBSD.org> |
INTON / INTOFF audit and cleanup.
No visible differences expected - there is a remote chance that some internal lossage may no longer occur in interactive shells that receive SIGINT (untrapped) at i
INTON / INTOFF audit and cleanup.
No visible differences expected - there is a remote chance that some internal lossage may no longer occur in interactive shells that receive SIGINT (untrapped) at inopportune times, but you would have had to have been very unlucky to have ever suffered from that.
show more ...
|
| #
4084f829 |
| 04-Feb-2019 |
kre <kre@NetBSD.org> |
PR bin/53919
Suppress shell error messages while expanding $ENV (which also causes errors while expanding $PS1 $PS2 and $PS4 to be suppressed as well).
This allows any random garbage that happens t
PR bin/53919
Suppress shell error messages while expanding $ENV (which also causes errors while expanding $PS1 $PS2 and $PS4 to be suppressed as well).
This allows any random garbage that happens to be in ENV to not cause noise when the shell starts (which is effectively all it did).
On a parse error (for any of those vars) we also use "" as the result, which will be a null prompt, and avoid attempting to open any file for ENV.
This does not in any way change what happens for a correctly parsed command substitution (either when it is executed when permitted for one of the prompts, or when it is not (which is always for ENV)) and commands run from those can still produce error output (but shell errors remain suppressed).
show more ...
|
| #
6b3f9583 |
| 21-Jan-2019 |
kre <kre@NetBSD.org> |
When we are about to execute something, and the traps are invalid (which means this is the very first execution in a new subshell) clear the traps completely, unless the command is "trap". We were
When we are about to execute something, and the traps are invalid (which means this is the very first execution in a new subshell) clear the traps completely, unless the command is "trap". We were allowing any special builtin, which was probably harmless, but not intended.
Also (though not required) permit "command trap" and "eval trap" and combinations thereof, because they might be useful, and there is no particular reason why not. This is all a part of making t=$(trap) work as POSIX requires, but almost nothing beyond that. The "trap" command must be alone (modulo eval and command) in the subshell for the exception to apply, no t=$(trap; echo) or anything like that.
Martijn Dekker asked for "command trap" to work (no idea why though, it converts "trap" from being a special builtin, to a normal one, which means an error won't cause the shell to exit ... if there's an error, the "trap" command won't do anything useful, and as we permit no more commands (for this special treatment) the shell is going to exit anyway, this difference is not really significant.
show more ...
|
| #
a582e232 |
| 09-Jan-2019 |
kre <kre@NetBSD.org> |
When an error occurs in a builtin from which we do not exit (a normal builtin, though those are not genrally an issue for this problem, or a special builtin that has been prefixed by "command") make
When an error occurs in a builtin from which we do not exit (a normal builtin, though those are not genrally an issue for this problem, or a special builtin that has been prefixed by "command") make sure that we discard any pending input that might have been queued up, but not yet processed.
We had the mechanism to fix this from when expansion of PS1 etc was added (which has a similar problem to deal with) - all taken from FreeBSD - but did not bother to use it here until now...
This fixes an error detected by newly added ATF tests of the eval builtin, where eval 'syntax error another command' would go ahead and evaluate "another command" which should not happen (note: only when there was a \n between the two).
show more ...
|
| #
13fc5c1b |
| 03-Dec-2018 |
kre <kre@NetBSD.org> |
Cleanup traps a bit - attempt to handle weird uses in traps, such as traps that issue break/continue/return to cause the loop/function executing when the trap occurred to break/continue/return, and g
Cleanup traps a bit - attempt to handle weird uses in traps, such as traps that issue break/continue/return to cause the loop/function executing when the trap occurred to break/continue/return, and generating the correct exit code from the shell including when a signal is caught, but the trap handler for it exits.
All that from FreeBSD.
Also make T=$(trap) work as it is supposed to (also trap -p).
For now this is handled by the same technique as $(jobs) - rather than clearing the traps in subshells, just mark them invalid, and then whenever they're invalid, clear them before executing anything other than the special blessed "trap" command. Eventually we will handle these using non-subshell command substitution instead (not creating a subshell environ when the commands in a command-sub alter nothing in the environment).
show more ...
|
| #
522d1631 |
| 03-Dec-2018 |
kre <kre@NetBSD.org> |
Fix "export -x" (and its consequences) to behave as originally intended (and as documented) rather than how it has been behaving (which was not very rational.) Since it is unlikely that anyone is u
Fix "export -x" (and its consequences) to behave as originally intended (and as documented) rather than how it has been behaving (which was not very rational.) Since it is unlikely that anyone is using this, the change should be mostly invisible.
While here, a couple of other minor cleanups: . One call of geteuid() is enough in choose_ps1() . Fix a typo in a comment . Improve appearance (whitspace changes) in find_var()
show more ...
|
| #
021ba509 |
| 03-Dec-2018 |
kre <kre@NetBSD.org> |
Revamp aliases - as dumb an idea as they are, if we're going to have them, they should work as documented, not cause core dumps, reference after free, incorrect replacements, failing to implement ali
Revamp aliases - as dumb an idea as they are, if we're going to have them, they should work as documented, not cause core dumps, reference after free, incorrect replacements, failing to implement alias after alias, ...
The big comment that ended: This is a good idea ------- ***NOT*** and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1 code (ie: came from the original import, even before 4.4-Lite was merged. That is, May 1994. And no-one in 24.5 years noticed (or at least complained about) all the bugs (or at least, most of them)).
With these changes, aliases ought to work (if you can call it that) as they are expected to by POSIX. Now if only we could get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD, (as was the previous change to alias.c, forgot ack in commit log for that one, apologies) but done a little differently, and perhaps with a slightly better outcome.
show more ...
|
| #
d0219581 |
| 30-Nov-2018 |
kre <kre@NetBSD.org> |
It is not only the EXIT trap we need to check for when deciding no fork is required, but any trap (dumb mistake...)
XXX - include in 48875 pullup to -8
|
| #
d7fa5d2f |
| 26-Nov-2018 |
kre <kre@NetBSD.org> |
Make it be that an empty command is treated as a regular builtin for the purposes of any redirects it might have -- ie: as posix requires, make the redirects appear to have been executed in a subshel
Make it be that an empty command is treated as a regular builtin for the purposes of any redirects it might have -- ie: as posix requires, make the redirects appear to have been executed in a subshell environment, so if one fails, aside from a diagnositc msg, all the running script sees is a command that failed ($? != 0), rather that having the shell exit which used to happen (the empty command was being treated as a special builtin).
Continue to treat the empty command as special for the purposes of var assigns it might contain (those are not executed in a sub-shell and persist) - an error there (eg: assigning to a readonly var) will continue to cause the shell (non-interactive shell) to exit.
This makes the NetBSD shell behave like all other (reasonably modern) shells - fix method (not the implementation, details differ) taken from FreeBSD who fixed this back in early 2010. Problem pointed out in (non-list) mail by Martijn Dekker.
show more ...
|
| #
c43d5e9f |
| 23-Nov-2018 |
kre <kre@NetBSD.org> |
Handle eval $'continue\ncommand' (and similar) in a loop correctly ... "command" should not be executed. (The issue affects multi-line eval strings only - ie: commands after the next \n are not skip
Handle eval $'continue\ncommand' (and similar) in a loop correctly ... "command" should not be executed. (The issue affects multi-line eval strings only - ie: commands after the next \n are not skipped).
Bug noted by Martijn Dekker in off-list e-mail.
Fix from FreeBSD: src/bin/sh/eval.c: Revision 272983 Sun Oct 12 13:12:06 2014 UTC by jilles
show more ...
|
| #
0db5b60c |
| 09-Oct-2018 |
kre <kre@NetBSD.org> |
When (about to) send the -x output for the end of a compound command (which has redirects, and so is included in -x output) use the -x/+x setting that existed when the comoound started, so if the sta
When (about to) send the -x output for the end of a compound command (which has redirects, and so is included in -x output) use the -x/+x setting that existed when the comoound started, so if the state of xtrace changes during the command we don't end up with just half of the -x output (either the intro, or the conclusion, depending on which way the change happened). [this also happens to avoid a core dump in the previous code, but that could have been done other ways, this way actually simplifies things (less code)]
show more ...
|
| #
ce53a30d |
| 25-Aug-2018 |
kre <kre@NetBSD.org> |
PR bin/53548
Deal with the new shell internal exit reason EXEXIT in the case of a shell which has vfork()'d. It takes a peculiar set of circumstances to get into a situation where this is ever rel
PR bin/53548
Deal with the new shell internal exit reason EXEXIT in the case of a shell which has vfork()'d. It takes a peculiar set of circumstances to get into a situation where this is ever relevant, but it can be done. See the PR for details.
show more ...
|
| #
70696c01 |
| 22-Aug-2018 |
kre <kre@NetBSD.org> |
Fix (hopefully) the problem reported on current-users by Patrick Welche. we had incorrect usage of setstackmark()/popstackmark()
There was an ancient idiom (imported from CSRG in 1993) where code ca
Fix (hopefully) the problem reported on current-users by Patrick Welche. we had incorrect usage of setstackmark()/popstackmark()
There was an ancient idiom (imported from CSRG in 1993) where code can do: setstackmark(&smark); loop until whatever condition { /* do lots of code */ popstackmark(&smark); } popstackmark(&smark);
The 1st (inner) popstackmark() resets the stack, conserving memory, The 2nd one is needed just in case the "whatever condition" was never true, and the first one was never executed.
This is (was) safe as all popstackmark() did was reset the stack. That could be done over and over again with no harm.
That is, until 2000 when a fix from FreeBSD for another problem was imported. That connected all the stack marks as a list (so they can be located). That caused the problem, as the idiom was not changed, now there is this list of marks, and popstackmark() was removing an entry.
It rarely (never?) caused any problems as the idiom was rarely used (the shell used to do loops like above, mostly, without the inner popstackmark()). Further, the stack mark list is only ever used when a memory block is realloc'd.
That is, until last weekend - with the recent set of changes.
Part of that copied code from FreeBSD introduced the idiom above into more functions - functions used much more, and with a greater possibility of stack marks being set on blocks that are realloc'd and so cause the problem. In the FreeBSD code, they changed the idiom, and always do a setstackmark() immediately after the inner popstackmark(). But not for reasons related to a list of stack marks, as in the intervening period, FreeBSD deleted that, but for another reason.
We do not have their issue, and I did not believe that their updated idiom was needed (I did some analysis of exactly this issue - just missed the important part!), and just continued using the old one. Hence Patrick's core dump....
The solution used here is to split popstackmark() into 2 halves, popstackmark() continues to do what it has (recently) done, but is now implemented as a call of (a new func) rststackmark() which does all the original work of popstackmark - but not removing the entry from the stack mark list (which remains in popstackmark()). Then in the idiom above, the inner popstackmark() turns into a call of rststackmark() so the stack is reset, but the stack mark list is unchanged. Tail recursion elimination makes this essentially free.
show more ...
|
| #
8a9a9619 |
| 19-Aug-2018 |
kre <kre@NetBSD.org> |
PR bin/48875 (is related, and ameliorated, but not exactly "fixed")
Import a whole set of tree evaluation enhancements from FreeBSD.
With these, before forking, the shell predicts (often) when all
PR bin/48875 (is related, and ameliorated, but not exactly "fixed")
Import a whole set of tree evaluation enhancements from FreeBSD.
With these, before forking, the shell predicts (often) when all it will have to do after forking (in the parent) is wait for the child and then exit with the status from the child, and in such a case simply does not fork, but rather allows the child to take over the parent's role.
This turns out to handle the particular test case from PR bin/48875 in such a way that it works as hoped, rather than as it did (the delay there was caused by an extra copy of the shell hanging around waiting for the background child to complete ... and keeping the command substitution stdout open, so the "real" parent had to wait in case more output appeared).
As part of doing this, redirection processing for compound commands gets moved out of evalsubshell() and into a new evalredir(), which allows us to properly handle errors occurring while performing those redirects, and not mishandle (as in simply forget) fd's which had been moved out of the way temporarily.
evaltree() has its degree of recursion reduced by making it loop to handle the subsequent operation: that is instead of (for any binop like ';' '&&' (etc)) where it used to evaltree(node->left); evaltree(node->right); return; it now does (kind of) next = node; while ((node = next) != NULL) { next = NULL;
if (node is a binary op) { evaltree(node->left); if appropriate /* if && test for success, etc */ next = node->right; continue; } /* similar for loops, etc */ } which can be a good saving, as while the left side (now) tends to be (usually) a simple (or simpleish) command, the right side can be many commands (in a command sequence like a; b; c; d; ... the node at the top of the tree will now have "a" as its left node, and the tree for b; c; d; ... as its right node - until now everything was evaluated recursively so it made no difference, and the tree was constructed the other way).
if/while/... statements are done similarly, recurse to evaluate the condition, then if the (or one of the) body parts is to be evaluated, set next to that, and loop (previously it recursed).
There is more to do in this area (particularly in the way that case statements are processed - we can avoid recursion there as well) but that can wait for another day.
While doing all of this we keep much better track of when the shell is just going to exit once the current tree is evaluated (with a new predicate at_eof() to tell us that we have, for sure, reached the end of the input stream, that is, this shell will, for certain, not be reading more command input) and use that info to avoid unneeded forks. For that we also need another new predicate (have_traps()) to determine of there are any caught traps which might occur - if there are, we need to remain to (potentially) handle them, so these optimisations will not occur (to make the issue in PR 48875 appear again, run the same code, but with a trap set to execute some code when a signal (or EXIT) occurs - note that the trap must be set in the appropriate level of sub-shell to have this effect, any caught traps are cleared in a subshell whenever one is created).
There is still work to be done to handle traps properly, whatever weirdness they do (some of which is related to some of this.)
These changes do not need man page updates, but 48875 does - an update to sh.1 will be forthcoming once it is decided what it should say...
Once again, all the heavy lifting for this set of changes comes directly (with thanks) from the FreeBSD shell.
XXX pullup-8 (but not very soon)
show more ...
|
| #
120267c3 |
| 19-Aug-2018 |
kre <kre@NetBSD.org> |
PR bin/48875
Revert the changes that were made 19 May 2016 (principally eval.c 1.125) and the bug fixes in subsequent days (eval.c 1.126 and 1.127) and also update some newer code that was added mor
PR bin/48875
Revert the changes that were made 19 May 2016 (principally eval.c 1.125) and the bug fixes in subsequent days (eval.c 1.126 and 1.127) and also update some newer code that was added more recently which acted in accordance with those changes (make that code be as it would have been if the changes now being reverted had never been made).
While the changes made did solve the problem, in a sense, they were never correct (see the PR for some discussion) and it had always been intended that they be reverted. However, in practical sh code, no issues were reported - until just recently - so nothing was done, until now...
After this commit, the validate_fn_redirects test case of the sh ATF test t_redir will fail. In particular, the subtest of that test case which is described in the source (of the test) as: This one is the real test for PR bin/48875 will fail.
Alternative changes, not to "fix" the problem in the PR, but to often avoid it will be coming very soon - after which that ATF test will succeed again.
XXX pullup-8
show more ...
|
| #
16ccf0ee |
| 14-Aug-2018 |
kre <kre@NetBSD.org> |
PR bin/42184 PR bin/52687 (detailing the same bug).
Fix "command not found" handling so that the error message goes to stderr (after any redirections are applied).
More importantly, in
foo > /tm
PR bin/42184 PR bin/52687 (detailing the same bug).
Fix "command not found" handling so that the error message goes to stderr (after any redirections are applied).
More importantly, in
foo > /tmp/junk
/tmp/junk should be created, before any attempt is made to execute (the assumed non-existing) "foo".
All this was always true for any command (not found command) containing a / in its name
foo/bar >/tmp/junk 2>>/tmp/errs
would have created /tmp/junk, then complained (in /tmp/errs) about foo/bar not being found. Now that happens for ordinary commands as well.
The fix (which I found when I saw differences between our code and FreeBSD's, where, for the benefit of PR 42184, this has been fixed, sometime in the past 9 years) is frighteningly simple. Simply do not short circuit execution (or print any error) when the initial lookup fails to find the command - it will fail anyway when we actually try running it. The cost is a (seemingly unnecessary, except that it really is) fork in this case.
This is what I had been planning, but I expected it would be much more difficult than it turned out....
XXX pullup-8
show more ...
|
| #
e2f17f9a |
| 25-Jul-2018 |
kre <kre@NetBSD.org> |
Fix several bugs in the command / type builtin ( including PR bin/48499 )
1. Make command -pv (and -pV) work (which is not as easy as the PR suggests it might be (the "check and cause error" was
Fix several bugs in the command / type builtin ( including PR bin/48499 )
1. Make command -pv (and -pV) work (which is not as easy as the PR suggests it might be (the "check and cause error" was there because it did not work, not in order to prevent it from working).
2. Stop -v and -V being both used (that makes no sense).
3. Stop the "type" builtin inheriting the args (-pvV) that "command" has (which it did, as when -v -or -V is used with command, it and type are implemented using the same code).
4. make "command -v word" DTRT for sh keywords (was treating them as an error).
5. Require at least one arg for "command -[vV]" or "type" else usage & error. Strictly this should also apply to "command" and "command -p" (no -v) but that's handled elsewhere, so perhaps some other time. Perhaps "command -v" (and -V) should be limited to 1 command name (where "type" can have many) as in the POSIX definitions, but I don't think that matters.
6. With "command -V alias", (or "type alias" which is the same thing), (but not "command -v alias") alter the output format, so we get ll is an alias for: ls -al instead of the old ll is an alias for ls -al (and note there was a space, for some reason, after "for")
That is, unless the alias value contains any \n characters, in which case (something approximating) the old multi-line format is retained. Also note: that if code wants to parse/use the value of an alias, it should be using the output of "alias name", not command or type.
Note that none of the above affects "command [-p] cmd" (no -v or -V options) only "command -[vV]" and "type".
Note also that the changes to eval.[ch] are merely to make syspath() visible in exec.c rather than static in eval.c
show more ...
|
| #
c7c0722a |
| 22-Jun-2018 |
kre <kre@NetBSD.org> |
Deal with ref after free found by ASAN when a function redefines itself, or some other function which is still active. This was a long known bug (fixed ages ago in the FreeBSD sh) which hadn't been f
Deal with ref after free found by ASAN when a function redefines itself, or some other function which is still active. This was a long known bug (fixed ages ago in the FreeBSD sh) which hadn't been fixed as in practice, the situation that causes the problem simply doesn't arise .. ASAN found it in the sh dotcmd tests which do have this odd "feature" in the way they are written (but where it never caused a problem, as the tests are so simple that no mem is ever allocated between when the old version of the function was deleted, and when it finished executing, so its code all remained intact, despite having been freed.)
The fix is taken from the FreeBSD sh.
XXX -- pullup-8 (after a while to ensure no other problems arise).
show more ...
|
| #
765ad10c |
| 17-Jun-2018 |
kre <kre@NetBSD.org> |
NFC: correct typo in a comment.
|
| #
ffc64c63 |
| 19-Nov-2017 |
kre <kre@NetBSD.org> |
Implement the -X option - an apparent variant of -x which sends all trace output to the stderr which existed when the -X option was (last) enabled. It also enables tracing by enabling -x (and when re
Implement the -X option - an apparent variant of -x which sends all trace output to the stderr which existed when the -X option was (last) enabled. It also enables tracing by enabling -x (and when reset, +X, also resets the 'x' flag (+x)). Note that it is still -x/+x which actually enables/disables the trace output. Hence "apparent variant" - what -X actually does (aside from setting -x) is just to lock the trace output, rather than having it follow wherever stderr is later redirected.
show more ...
|
| #
f07d3f9b |
| 29-Sep-2017 |
kre <kre@NetBSD.org> |
DEBUG only changes (non-debug, ie: normal, shell unaffected) Add a little extra info in a few of the trace messages.
|
| #
3b297678 |
| 30-Jun-2017 |
kre <kre@NetBSD.org> |
Include redirections in trace output from "set -x"
|
| #
87d90665 |
| 19-Jun-2017 |
kre <kre@NetBSD.org> |
Another fix from FreeBSD (this one from April 2009).
When processing a string (as in eval, trap, or sh -c) don't allow trailing \n's to destroy the exit status of the last command executed.
That is
Another fix from FreeBSD (this one from April 2009).
When processing a string (as in eval, trap, or sh -c) don't allow trailing \n's to destroy the exit status of the last command executed.
That is: sh -c 'false
' echo $? should produce 1, not 0.
show more ...
|
| #
3892a5b0 |
| 19-Jun-2017 |
kre <kre@NetBSD.org> |
Fix from FreeBSD (applied there in July 2008...)
Don't dump core with input like sh -c 'x=; echo >&$x' - that is where the word after a >& or <& redirect expands to nothing at all.
|
| #
20013177 |
| 17-Jun-2017 |
kre <kre@NetBSD.org> |
NFC - DEBUG changes, update this to new TRACE method. KNF - white space and comment formatting.
|