1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/cmd/ksh93/tests
Martijn Dekker 50db00e136 Fix subshell trap integrity, e.g. re-trapping a signal in subshell
Ksh handles local traps in virtual subshells the same way as local
traps in ksh-style shell functions, which can cause incorrect
operation.

Reproducer script:

	trap 'echo "parent shell trap"; exit 0' USR1
	(trap 'echo "subshell trap"' USR1; kill -USR1 $$)
	echo wrong

Output on every ksh93 version: 'wrong'
Output on every other shell: 'parent shell trap'

The ksh93 output is wrong because $$ is the PID of the main shell,
therefore 'kill -USR1 $$' from a subshell needs to issue SIGUSR1 to
the main shell and trigger the 'echo SIGUSR1' trap.

This is an inevitable consequence of processing signals in a
virtual subshell. Signals are a process-wide property, but a
virtual subshell and the parent shell share the same process.
Therefore it is not possible to distinguish between the parent
shell and subshell trap.

This means virtual subshells are fundamentally incompatible with
receiving signals. No workaround can make this work properly.

Ksh could either assume the signal needs to be caught by the
subshell trap (wrong in this case, but right in others) or by the
parent shell trap. But it does neither and just gives up and does
nothing, which I suppose is the least bad way of doing it wrong.

As another example, consider a subshell that traps a signal, then
passes its own process ID (as of 9de65210, that's ${.sh.pid}) to
another process to say "here is where to signal me". A virtual
subshell will send it the PID that it shares with the the parent
shell. Even if a virtual subshell receives the signal correctly, it
may fork mid-execution afterwards, depending on the commands that
it runs (and this varies by implementation as we fix or work around
bugs). So its PID could be invalidated at any time.

Forking a virtual subshell at the time of trapping a signal is the
only way to ensure a persistent PID and correct operation.

src/cmd/ksh93/bltins/trap.c: b_trap():
- Fork when trapping (or ignoring) a signal in a virtual subshell.
  (There's no need to fork when trapping a pseudosignal.)

src/cmd/ksh93/tests/signal.sh:
- Add tests. These are simplified versions of tests already there,
  which issued 'kill' as a background job. Currently, running a
  background job causes a virtual subshell to fork before forking
  the 'kill' background job (or *any* background job, see e3d7bf1d)
  -- an ugly partial workaround that I believe just became
  redundant and which I will remove in the next commit.
2022-06-14 01:33:24 +01:00
..
_common tests/leaks.sh: redesign with a more robust testing algorithm 2021-12-28 17:47:29 +00:00
alias.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
append.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
arith.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
arrays.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
arrays2.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
attributes.sh Honour attribs for assignments preceding sp. builtins, POSIX functs 2022-06-03 23:28:28 +01:00
basic.sh Add error message for ambiguous long-form option abbreviation 2022-06-10 01:11:46 +01:00
bracket.sh Another round of minor tweaks and cleanups 2022-06-09 03:02:06 +01:00
builtins.sh [v1.0] posix: don't zero-pad 2nds (re: 5c677a4c, 70fc1da7, b1a41311) 2022-06-12 16:16:11 +01:00
case.sh Update copyright years in files changed since 1st Jan 2022 2022-01-30 20:49:04 +00:00
comvar.sh Another round of accumulated minor fixes and cleanups 2022-03-11 21:20:32 +01:00
comvario.sh Another round of accumulated minor fixes and cleanups 2022-03-11 21:20:32 +01:00
coprocess.sh tests/coprocess.sh: activate known intermittent fail as warning 2022-06-04 11:53:46 +01:00
cubetype.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
enum.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
exit.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
expand.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
functions.sh Honour attribs for assignments preceding sp. builtins, POSIX functs 2022-06-03 23:28:28 +01:00
glob.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
grep.sh Update copyright years in files changed since 1st Jan 2022 2022-01-30 20:49:04 +00:00
heredoc.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
io.sh Another round of accumulated minor fixes and cleanups 2022-03-11 21:20:32 +01:00
jobs.sh ...and now make it work with shcomp (re: aed5c6d7) 2021-03-13 19:27:15 +00:00
leaks.sh libast: optget(3): Fix memory leak in --help/--man info 2022-03-11 21:24:08 +01:00
locale.sh fix radix point regress test bug (re: a0effeb0) 2022-06-05 17:53:53 +01:00
math.sh Fix xtrace (shtests -x) for the regression tests 2021-05-14 19:56:11 +02:00
nameref.sh Yet more misc. cleanups; rm SHOPT_PFSH, SHOPT_TYPEDEF 2022-02-10 21:04:56 +00:00
namespace.sh Correctly exit from namespace on error (re: f73b8617) 2022-06-02 03:28:41 +01:00
options.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
path.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
pointtype.sh Another build system overhaul (re: 35672208, 580ff616, 6cc2f6a0) 2022-06-12 05:47:02 +01:00
posix.sh [v1.0] posix: don't zero-pad 2nds (re: 5c677a4c, 70fc1da7, b1a41311) 2022-06-12 16:16:11 +01:00
pty.sh Fix completion following $'foo\'bar' 2022-06-06 03:13:13 +01:00
quoting.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
quoting2.sh Fix line continuation within command substitutions 2022-05-22 00:23:54 +01:00
readcsv.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
readonly.sh Another round of minor tweaks and cleanups 2022-06-09 03:02:06 +01:00
recttype.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
restricted.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
return.sh Fix crash in xtrace while processing here-document (re: d7cada7b) 2021-12-27 04:02:25 +00:00
select.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
sh_match.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
shtests Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
sigchld.sh tests/sigchild.sh: try to fix intermittent fail (re: dc80f40d) 2022-02-17 19:37:41 +00:00
signal.sh Fix subshell trap integrity, e.g. re-trapping a signal in subshell 2022-06-14 01:33:24 +01:00
statics.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
subshell.sh Fix a few minor issues (#473) 2022-03-11 21:18:42 +01:00
substring.sh Backport ksh93v- regression tests and fix various regression test bugs (#472) 2022-03-11 21:15:55 +01:00
tilde.sh Update copyright years in files changed since 1st Jan 2022 2022-01-30 20:49:04 +00:00
timetype.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
treemove.sh Fix multiple bugs in .sh.match (#455) 2022-02-10 21:04:23 +00:00
types.sh Error on defining disc for undeclared type member (re: 87088361) 2022-06-08 01:12:23 +01:00
variables.sh remove ( simple_command & ) optimisation (re: e3d7bf1d) 2022-06-14 01:32:33 +01:00
vartree1.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
vartree2.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00