Skip to content

Commit 6647917

Browse files
author
Chet Ramey
committed
Bash-5.2 patch 14: process additional terminating signals when running the EXIT trap after a terminating signal
1 parent 52f2cda commit 6647917

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

execute_cmd.c

+1
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,7 @@ execute_case_command (case_command)
36243624
free (pattern);
36253625

36263626
dispose_words (es);
3627+
QUIT;
36273628

36283629
if (match)
36293630
{

patchlevel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
2626
looks for to find the patch level (for the sccs version string). */
2727

28-
#define PATCHLEVEL 13
28+
#define PATCHLEVEL 14
2929

3030
#endif /* _PATCHLEVEL_H_ */

sig.c

+23-5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static SigHandler *old_winch = (SigHandler *)SIG_DFL;
9494
#endif
9595

9696
static void initialize_shell_signals PARAMS((void));
97+
static void kill_shell PARAMS((int));
9798

9899
void
99100
initialize_signals (reinit)
@@ -486,6 +487,8 @@ restore_sigmask ()
486487
#endif
487488
}
488489

490+
static int handling_termsig = 0;
491+
489492
sighandler
490493
termsig_sighandler (sig)
491494
int sig;
@@ -532,6 +535,14 @@ termsig_sighandler (sig)
532535
sig == terminating_signal)
533536
terminate_immediately = 1;
534537

538+
/* If we are currently handling a terminating signal, we have a couple of
539+
choices here. We can ignore this second terminating signal and let the
540+
shell exit from the first one, or we can exit immediately by killing
541+
the shell with this signal. This code implements the latter; to implement
542+
the former, replace the kill_shell(sig) with return. */
543+
if (handling_termsig)
544+
kill_shell (sig); /* just short-circuit now */
545+
535546
terminating_signal = sig;
536547

537548
if (terminate_immediately)
@@ -564,16 +575,13 @@ void
564575
termsig_handler (sig)
565576
int sig;
566577
{
567-
static int handling_termsig = 0;
568-
int i, core;
569-
sigset_t mask;
570-
571578
/* Simple semaphore to keep this function from being executed multiple
572579
times. Since we no longer are running as a signal handler, we don't
573580
block multiple occurrences of the terminating signals while running. */
574581
if (handling_termsig)
575582
return;
576-
handling_termsig = 1;
583+
584+
handling_termsig = terminating_signal; /* for termsig_sighandler */
577585
terminating_signal = 0; /* keep macro from re-testing true. */
578586

579587
/* I don't believe this condition ever tests true. */
@@ -613,6 +621,16 @@ termsig_handler (sig)
613621

614622
run_exit_trap (); /* XXX - run exit trap possibly in signal context? */
615623

624+
kill_shell (sig);
625+
}
626+
627+
static void
628+
kill_shell (sig)
629+
int sig;
630+
{
631+
int i, core;
632+
sigset_t mask;
633+
616634
/* We don't change the set of blocked signals. If a user starts the shell
617635
with a terminating signal blocked, we won't get here (and if by some
618636
magic chance we do, we'll exit below). What we do is to restore the

0 commit comments

Comments
 (0)