From ff46268c6aaa1fd989485a21e9b679124d3add3f Mon Sep 17 00:00:00 2001 From: kre Date: Mon, 9 Dec 2019 00:14:30 +0000 Subject: [PATCH] PR bin/54743 If a builtin command or function is the final command intended to be executed, and is interrupted by a caught signal, the trap handler for that signal was not executed - the shell simply exited (an exit trap handler would still have been run - if there was one the handler for the signal may have been invoked during the execution of the exit trap handler, which, if it happened, is incorrect sequencing). Now, if we're exiting, and there are pending signals, run their handlers just before running the EXIT trap handler, if any. There are almost certainly plenty more issues with traps that need solving. Later, XXX pullup -9 (-8 is too different in this area, and this problem suitably obscure, that we won't bother) (the -7 sh is simply obsolete). --- bin/sh/trap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/sh/trap.c b/bin/sh/trap.c index 6a98f9a8bc23..8fcaee09d056 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.52 2019/04/25 03:54:10 kre Exp $ */ +/* $NetBSD: trap.c,v 1.53 2019/12/09 00:14:30 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; #else -__RCSID("$NetBSD: trap.c,v 1.52 2019/04/25 03:54:10 kre Exp $"); +__RCSID("$NetBSD: trap.c,v 1.53 2019/12/09 00:14:30 kre Exp $"); #endif #endif /* not lint */ @@ -854,6 +854,12 @@ exitshell_savedstatus(void) } exitstatus = exiting_status; + if (pendingsigs && !setjmp(loc.loc)) { + handler = &loc; + + dotrap(); + } + if (!setjmp(loc.loc)) { handler = &loc;