From efd1946c355ec8fd033b7b17bb0baf36cf7cfd7c Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Wed, 30 Oct 2013 21:36:15 +0000 Subject: [PATCH] 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. --- bin/sh/trap.c | 4 +++- tools/regression/bin/sh/builtins/trap13.0 | 8 ++++++++ tools/regression/bin/sh/builtins/trap14.0 | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tools/regression/bin/sh/builtins/trap13.0 create mode 100644 tools/regression/bin/sh/builtins/trap14.0 diff --git a/bin/sh/trap.c b/bin/sh/trap.c index 3fc85668c64..1b2c3544acd 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -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; } diff --git a/tools/regression/bin/sh/builtins/trap13.0 b/tools/regression/bin/sh/builtins/trap13.0 new file mode 100644 index 00000000000..d90eb08eb24 --- /dev/null +++ b/tools/regression/bin/sh/builtins/trap13.0 @@ -0,0 +1,8 @@ +# $FreeBSD$ + +{ + trap 'exit 0' INT + ${SH} -c 'kill -INT $PPID' + exit 3 +} & +wait $! diff --git a/tools/regression/bin/sh/builtins/trap14.0 b/tools/regression/bin/sh/builtins/trap14.0 new file mode 100644 index 00000000000..97cce8d0d24 --- /dev/null +++ b/tools/regression/bin/sh/builtins/trap14.0 @@ -0,0 +1,10 @@ +# $FreeBSD$ + +{ + trap - INT + ${SH} -c 'kill -INT $PPID' & + wait +} & +wait $! +r=$? +[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ]