sh: Allow trapping SIGINT/SIGQUIT after ignore because of '&'.

If job control is not enabled, background jobs started with  ... &  ignore
SIGINT and SIGQUIT so that they are not affected by such signals that are
intended for the foreground job. However, this should not prevent
reassigning a different action for these signals (as if the shell invocation
inherited these signal actions from its parent).

Austin group issue #751

Example:
  { trap - INT; exec sleep 10; } & wait
A Ctrl+C should terminate the sleep command.
This commit is contained in:
Jilles Tjoelker 2013-10-30 21:36:15 +00:00
parent 46bcf11d50
commit efd1946c35
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=257399
3 changed files with 21 additions and 1 deletions

View File

@ -362,10 +362,12 @@ void
ignoresig(int signo)
{
if (sigmode[signo] == 0)
setsignal(signo);
if (sigmode[signo] != S_IGN && sigmode[signo] != S_HARD_IGN) {
signal(signo, SIG_IGN);
sigmode[signo] = S_IGN;
}
sigmode[signo] = S_HARD_IGN;
}

View File

@ -0,0 +1,8 @@
# $FreeBSD$
{
trap 'exit 0' INT
${SH} -c 'kill -INT $PPID'
exit 3
} &
wait $!

View File

@ -0,0 +1,10 @@
# $FreeBSD$
{
trap - INT
${SH} -c 'kill -INT $PPID' &
wait
} &
wait $!
r=$?
[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ]