From 0bffc94d571bbd794a36aafc51ec649a26fe436f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 21 Jul 2014 16:28:54 +0200 Subject: Issue #22018: signal.set_wakeup_fd() now raises an OSError instead of a ValueError on fstat() failure. --- Lib/test/test_signal.py | 6 +++--- Misc/NEWS | 3 +++ Modules/signalmodule.c | 14 +++++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index de3b40f..e40dfb5 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -252,14 +252,14 @@ class WakeupFDTests(unittest.TestCase): def test_invalid_fd(self): fd = support.make_bad_fd() - self.assertRaises(ValueError, signal.set_wakeup_fd, fd) + self.assertRaises(OSError, signal.set_wakeup_fd, fd) def test_set_wakeup_fd_result(self): r1, w1 = os.pipe() - os.close(r1) + self.addCleanup(os.close, r1) self.addCleanup(os.close, w1) r2, w2 = os.pipe() - os.close(r2) + self.addCleanup(os.close, r2) self.addCleanup(os.close, w2) signal.set_wakeup_fd(w1) diff --git a/Misc/NEWS b/Misc/NEWS index 5a8d162..cd4ad67 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,9 @@ Core and Builtins Library ------- +- Issue #22018: signal.set_wakeup_fd() now raises an OSError instead of a + ValueError on ``fstat()`` failure. + - Issue #21044: tarfile.open() now handles fileobj with an integer 'name' attribute. Based on patch by Martin Panter. diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index cf4ba61..c4f0121 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -437,12 +437,20 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args) return NULL; } #endif - if (fd != -1 && (!_PyVerify_fd(fd) || fstat(fd, &buf) != 0)) { - PyErr_SetString(PyExc_ValueError, "invalid fd"); - return NULL; + + if (fd != -1) { + if (!_PyVerify_fd(fd)) { + PyErr_SetString(PyExc_ValueError, "invalid fd"); + return NULL; + } + + if (fstat(fd, &buf) != 0) + return PyErr_SetFromErrno(PyExc_OSError); } + old_fd = wakeup_fd; wakeup_fd = fd; + return PyLong_FromLong(old_fd); } -- cgit v0.12