diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-11-05 19:47:27 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-11-05 19:47:27 (GMT) |
commit | 39a65915076bb9c3719813f9d079925d661cdbd5 (patch) | |
tree | 7b1f22473fe4c5c1af7ef560855a50bd11095775 /Modules | |
parent | a078115434c58b2dce4cec82f3c2a90711166d60 (diff) | |
download | cpython-39a65915076bb9c3719813f9d079925d661cdbd5.zip cpython-39a65915076bb9c3719813f9d079925d661cdbd5.tar.gz cpython-39a65915076bb9c3719813f9d079925d661cdbd5.tar.bz2 |
Issue #10311: The signal module now restores errno before returning from
its low-level signal handler. Patch by Hallvard B Furuseth.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/signalmodule.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 4691285..0e7fd65 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -169,16 +169,20 @@ checksignals_witharg(void * unused) static void signal_handler(int sig_num) { -#ifdef WITH_THREAD -#ifdef WITH_PTH + int save_errno = errno; + +#if defined(WITH_THREAD) && defined(WITH_PTH) if (PyThread_get_thread_ident() != main_thread) { pth_raise(*(pth_t *) main_thread, sig_num); - return; } + else #endif + { +#ifdef WITH_THREAD /* See NOTES section above */ - if (getpid() == main_pid) { + if (getpid() == main_pid) #endif + { Handlers[sig_num].tripped = 1; /* Set is_tripped after setting .tripped, as it gets cleared in PyErr_CheckSignals() before .tripped. */ @@ -186,24 +190,26 @@ signal_handler(int sig_num) Py_AddPendingCall(checksignals_witharg, NULL); if (wakeup_fd != -1) write(wakeup_fd, "\0", 1); -#ifdef WITH_THREAD } -#endif + +#ifndef HAVE_SIGACTION #ifdef SIGCHLD - if (sig_num == SIGCHLD) { - /* To avoid infinite recursion, this signal remains - reset until explicit re-instated. - Don't clear the 'func' field as it is our pointer - to the Python handler... */ - return; - } + /* To avoid infinite recursion, this signal remains + reset until explicit re-instated. + Don't clear the 'func' field as it is our pointer + to the Python handler... */ + if (sig_num != SIGCHLD) #endif -#ifndef HAVE_SIGACTION /* If the handler was not set up with sigaction, reinstall it. See * Python/pythonrun.c for the implementation of PyOS_setsig which * makes this true. See also issue8354. */ PyOS_setsig(sig_num, signal_handler); #endif + } + + /* Issue #10311: asynchronously executing signal handlers should not + mutate errno under the feet of unsuspecting C code. */ + errno = save_errno; } |