Skip to content

Commit

Permalink
tests/kill4: Fix tests with wrong assumption
Browse files Browse the repository at this point in the history
Previously, some tests in kill4-p.tst depended on traps reacting to a
signal sent by the shell. Since the traps were set in subshells, the
processes executing the trap built-in might not be the direct child
processes of the shell. In that case, the children were terminated by
the signal, possibly before the subshells responded to the signal,
causing the subsequent wait built-in to return too early in the main
shell process.

To resolve this issue, the test cases are rewritten without using traps.
  • Loading branch information
magicant committed Jan 31, 2024
1 parent 5045f62 commit d8c9e8b
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions tests/kill4-p.tst
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,34 @@ setup 'halt() while kill -s CONT $$; do sleep 1; done'
mkfifo fifo1 fifo2 fifo3

test_oE 'sending signal to background job' -m
(trap 'echo 1; exit' USR1; >fifo1; halt) |
(trap 'echo 2; cat; exit' USR1; >fifo2; halt) |
(trap 'echo 3; cat; exit' USR1; >fifo3; halt) &
# The subshells stop at the redirections, waiting for the unopened FIFOs.
(>fifo1; echo not reached 1 >&2) |
(>fifo2; echo not reached 2 >&2) |
(>fifo3; echo not reached 3 >&2) &
halt &
<fifo1 <fifo2 <fifo3
kill -s USR1 %'(trap'
wait %'(trap'
kill -s USR1 '%?echo'
wait '%?echo'
kill -l $?
kill -s USR2 %halt
wait %halt
kill -l $?
__IN__
3
2
1
USR1
USR2
__OUT__

test_oE 'sending to multiple processes' -m
(trap 'echo; exit' TERM; >fifo1; halt X) &
(trap 'echo; exit' TERM; >fifo2; halt Y) &
<fifo1 <fifo2
kill '%?X' $!
wait '%?X' $!
# The subshells stop at the redirections, waiting for the unopened FIFOs.
(>fifo1; echo not reached 1 >&2) &
(>fifo2; echo not reached 2 >&2) &
kill '%?fifo1' '%?fifo2'
wait '%?fifo1'
kill -l $?
wait '%?fifo2'
kill -l $?
__IN__


TERM
TERM
__OUT__

)
Expand Down

0 comments on commit d8c9e8b

Please sign in to comment.