bpo-30654: Do not reset SIGINT handler to SIG_DFL in finisignal (GH-7146) (GH-7306)

(cherry picked from commit e905c84494)

Co-authored-by: pkerling <pkerling@casix.org>
This commit is contained in:
Miss Islington (bot) 2018-06-01 03:50:24 -07:00 committed by Antoine Pitrou
parent 3dd802d8f2
commit 623b439abe
2 changed files with 4 additions and 12 deletions

View file

@ -0,0 +1,2 @@
Fixed reset of the SIGINT handler to SIG_DFL on interpreter shutdown even
when there was a custom handler set previously. Patch by Philipp Kerling.

View file

@ -118,13 +118,6 @@ static PyObject *DefaultHandler;
static PyObject *IgnoreHandler; static PyObject *IgnoreHandler;
static PyObject *IntHandler; static PyObject *IntHandler;
/* On Solaris 8, gcc will produce a warning that the function
declaration is not a prototype. This is caused by the definition of
SIG_DFL as (void (*)())0; the correct declaration would have been
(void (*)(int))0. */
static PyOS_sighandler_t old_siginthandler = SIG_DFL;
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
static HANDLE sigint_event = NULL; static HANDLE sigint_event = NULL;
#endif #endif
@ -1291,7 +1284,7 @@ PyInit__signal(void)
/* Install default int handler */ /* Install default int handler */
Py_INCREF(IntHandler); Py_INCREF(IntHandler);
Py_SETREF(Handlers[SIGINT].func, IntHandler); Py_SETREF(Handlers[SIGINT].func, IntHandler);
old_siginthandler = PyOS_setsig(SIGINT, signal_handler); PyOS_setsig(SIGINT, signal_handler);
} }
#ifdef SIGHUP #ifdef SIGHUP
@ -1497,14 +1490,11 @@ finisignal(void)
int i; int i;
PyObject *func; PyObject *func;
PyOS_setsig(SIGINT, old_siginthandler);
old_siginthandler = SIG_DFL;
for (i = 1; i < NSIG; i++) { for (i = 1; i < NSIG; i++) {
func = Handlers[i].func; func = Handlers[i].func;
_Py_atomic_store_relaxed(&Handlers[i].tripped, 0); _Py_atomic_store_relaxed(&Handlers[i].tripped, 0);
Handlers[i].func = NULL; Handlers[i].func = NULL;
if (i != SIGINT && func != NULL && func != Py_None && if (func != NULL && func != Py_None &&
func != DefaultHandler && func != IgnoreHandler) func != DefaultHandler && func != IgnoreHandler)
PyOS_setsig(i, SIG_DFL); PyOS_setsig(i, SIG_DFL);
Py_XDECREF(func); Py_XDECREF(func);