Skip to content

bpo-30654: Do not reset SIGINT handler to SIG_DFL in finisignal #7146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 2 additions & 12 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ static PyObject *DefaultHandler;
static PyObject *IgnoreHandler;
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
static HANDLE sigint_event = NULL;
#endif
Expand Down Expand Up @@ -1336,7 +1329,7 @@ PyInit__signal(void)
/* Install default int handler */
Py_INCREF(IntHandler);
Py_SETREF(Handlers[SIGINT].func, IntHandler);
old_siginthandler = PyOS_setsig(SIGINT, signal_handler);
PyOS_setsig(SIGINT, signal_handler);
}

#ifdef SIGHUP
Expand Down Expand Up @@ -1542,14 +1535,11 @@ finisignal(void)
int i;
PyObject *func;

PyOS_setsig(SIGINT, old_siginthandler);
old_siginthandler = SIG_DFL;

for (i = 1; i < NSIG; i++) {
func = Handlers[i].func;
_Py_atomic_store_relaxed(&Handlers[i].tripped, 0);
Handlers[i].func = NULL;
if (i != SIGINT && func != NULL && func != Py_None &&
if (func != NULL && func != Py_None &&
func != DefaultHandler && func != IgnoreHandler)
PyOS_setsig(i, SIG_DFL);
Py_XDECREF(func);
Expand Down