summaryrefslogtreecommitdiffstats
path: root/Modules/signalmodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-08-17 18:27:56 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-08-17 18:27:56 (GMT)
commit6f6ec37838b424c5d5ccef9a640ad02b7d1cb92f (patch)
treeea727add92c9765d5e33d37a563a3d0deba30e4e /Modules/signalmodule.c
parentf920a1c1f132adb10fe81ea430f08c7b61d5cc9d (diff)
downloadcpython-6f6ec37838b424c5d5ccef9a640ad02b7d1cb92f.zip
cpython-6f6ec37838b424c5d5ccef9a640ad02b7d1cb92f.tar.gz
cpython-6f6ec37838b424c5d5ccef9a640ad02b7d1cb92f.tar.bz2
Issue #16105: When a signal handler fails to write to the file descriptor registered with ``signal.set_wakeup_fd()``, report an exception instead of ignoring the error.
Diffstat (limited to 'Modules/signalmodule.c')
-rw-r--r--Modules/signalmodule.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 0810633..bc99f23 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -175,15 +175,31 @@ checksignals_witharg(void * unused)
return PyErr_CheckSignals();
}
+static int
+report_wakeup_error(void *data)
+{
+ int save_errno = errno;
+ errno = (int) (Py_intptr_t) data;
+ PyErr_SetFromErrno(PyExc_OSError);
+ PySys_WriteStderr("Exception ignored when trying to write to the "
+ "signal wakeup fd:\n");
+ PyErr_WriteUnraisable(NULL);
+ errno = save_errno;
+ return 0;
+}
+
static void
trip_signal(int sig_num)
{
unsigned char byte;
+ int rc = 0;
Handlers[sig_num].tripped = 1;
if (wakeup_fd != -1) {
byte = (unsigned char)sig_num;
- write(wakeup_fd, &byte, 1);
+ while ((rc = write(wakeup_fd, &byte, 1)) == -1 && errno == EINTR);
+ if (rc == -1)
+ Py_AddPendingCall(report_wakeup_error, (void *) (Py_intptr_t) errno);
}
if (is_tripped)
return;