NetBSD/bin/sh
kre 8821fc2c7a Related to PR bin/48875
Correct an issue found by Oguz <oguzismailuysal@gmail.com> and reported
in e-mail (on the bug-bash list initially!) with the code changed to deal
with PR bin/48875

With:

	 sh -c 'echo start at $SECONDS;
			(sleep 3 & (sleep 1& wait) );
		echo end at $SECONDS'

The shell should say "start at 0\nend at 1\n", but instead (before
this fix, in -9 and HEAD, but not -8) does "start at 0\nend at 3\n"
(Not in -8 as the 48875 changes were never pulled up)>

There was an old problem, fixed years ago, which cause the same symptom,
related to the way the jobs table was cleared (or not) in subshells, and
it seemed like that might have resurfaced.

But not so, the issue here is the sub-shell elimination, which was part
of the 48875 "fix" (not really, it wasn't really a bug, just sub-optimal
and unexpected behaviour).

What the shell actually has been running in this case is:

	 sh -c 'echo start at $SECONDS;
			(sleep 3 & sleep 1& wait );
		echo end at $SECONDS'

as the inner subshell was deemed unnecessary - all its parent would
do is wait for its exit status, and then exit with that status - we
may as well simply replace the current sub-shell with the new one,
let it do its thing, and we're done...

But not here, the running "sleep 3" will remain a child of that merged
sub-shell, and the "wait" will thus wait for it, along with the sleep 1
which is all it should be seeing.

For now, fix this by not eliminating a sub-shell if there are existing
unwaited upon children in the current one.  It might be possible to
simply disregard the old child for the purposes of wait (and "jobs", etc,
all cmds which look at the jobs table) but the bookkeeping required to
make that work reliably is likely to take some time to get correct...

Along with this fix comes a fix to DEBUG mode shells, which, in situations
like this, could dump core in the debug code if the relevant tracing was
enabled, and add a new trace for when the jobs table is cleared (which was
added predating the discovery of the actual cause of this issue, but seems
worth keeping.)   Neither of these changes have any effect on shells
compiled normally.

XXX pullup -9
2021-04-04 13:24:07 +00:00
..
bltin
funcs
USD.doc Fix "every" typo in quote from The Mythical Man-Month 2018-09-14 05:59:10 +00:00
alias.c Allocate alias pointers for qsort() to use on the stack, rather than 2019-02-09 09:11:07 +00:00
alias.h Revamp aliases - as dumb an idea as they are, if we're going 2018-12-03 06:40:26 +00:00
arith_token.c
arith_tokens.h
arithmetic.c
arithmetic.h
builtins.def Add the "specialvar" built-in command. Discussed (well, mentioned 2019-02-14 11:15:24 +00:00
cd.c
cd.h
error.c PR bin/53919 2019-02-04 11:16:41 +00:00
error.h PR bin/53919 2019-02-04 11:16:41 +00:00
eval.c Related to PR bin/48875 2021-04-04 13:24:07 +00:00
eval.h PR bin/53919 2019-02-04 11:16:41 +00:00
exec.c PR bin/55979 2021-02-16 15:30:12 +00:00
exec.h
expand.c Remove a redundant set of parentheses that were added (along with a 2020-08-01 17:56:56 +00:00
expand.h When expanding a here-doc (NXHERE - the type with an unquoted end delim) 2020-02-13 05:19:05 +00:00
histedit.c Remove a function prototype which was added to <histedit.h> in 2005. 2019-02-10 19:21:52 +00:00
init.h
input.c PR bin/55979 2021-02-16 15:30:26 +00:00
input.h PR bin/48875 (is related, and ameliorated, but not exactly "fixed") 2018-08-19 23:50:27 +00:00
jobs.c Related to PR bin/48875 2021-04-04 13:24:07 +00:00
jobs.h Related to PR bin/48875 2021-04-04 13:24:07 +00:00
machdep.h
mail.c
mail.h
main.c bin/sh: Fixes -Werror=shadow causing build breaks. 2020-02-07 01:25:08 +00:00
main.h When forking a child shell, arrange for errors/exit to always unwind 2018-12-03 02:38:30 +00:00
Makefile Change the (commented out) setting of -DDEBUG to the form that 2018-10-28 18:13:47 +00:00
memalloc.c INTON / INTOFF audit and cleanup. 2019-02-09 03:35:55 +00:00
memalloc.h Fix (hopefully) the problem reported on current-users by Patrick Welche. 2018-08-22 20:08:54 +00:00
miscbltin.c
miscbltin.h
mkbuiltins
mkinit.sh Use printf, rather than echo (via echo redefined as a function that 2018-12-05 09:20:18 +00:00
mknodenames.sh In the older debug code (not using the new macros added in the 2018-08-18 03:09:37 +00:00
mknodes.sh Add some error checking, and stop assuming what the input 2019-01-19 13:08:50 +00:00
mkoptions.sh
mktokens
myhistedit.h
mystring.c
mystring.h
nodes.c.pat
nodetypes
option.list Avoid long option names that differ only in character case. 2018-11-23 20:40:06 +00:00
options.c Oops, the previous didn't do what was promised. Rather that ignoring 2020-02-05 14:56:25 +00:00
options.h
output.c
output.h
parser.c For now, probably forever, prohibit unquoted $ and ` in the names of 2020-08-19 22:41:47 +00:00
parser.h Delete a no-longer-used #define that referred to a struct field that 2019-02-13 21:40:50 +00:00
redir.c The previous commit was obviously made by a broken mindless automoton 2019-03-01 06:15:01 +00:00
redir.h Don't define max_user_fd in the header. 2020-04-03 16:22:23 +00:00
sh.1 Remove superfluous Ed. 2020-09-18 07:21:26 +00:00
shell.h NFCI - DEBUG mode only change. 2019-01-22 13:48:28 +00:00
show.c DEBUG mode only change. When pretty-printing a word from a parse 2019-02-14 13:27:59 +00:00
show.h
syntax.c Add a couple of comments. NFC. 2019-02-04 09:56:48 +00:00
syntax.h Finish the fixes from Feb 4 for handling of random data that 2019-02-27 04:10:56 +00:00
TOUR
trap.c Be less conservative about when we do clear_traps() when we have 2020-08-20 23:09:56 +00:00
trap.h Make pendingsigs forward declaration match the definition. 2018-12-03 10:53:29 +00:00
var.c Add the "specialvar" built-in command. Discussed (well, mentioned 2019-02-14 11:15:24 +00:00
var.h Alter a design botch when magic (self modifying) variables 2018-12-04 14:03:30 +00:00
version.h The time has come, the Walrus said... (but no shoes, 2018-12-12 12:16:42 +00:00