(original) (raw)

changeset: 91745:42cf963e3ab1 user: Victor Stinner victor.stinner@gmail.com date: Mon Jul 21 16:28:54 2014 +0200 files: Lib/test/test_signal.py Misc/NEWS Modules/signalmodule.c description: Issue #22018: signal.set_wakeup_fd() now raises an OSError instead of a ValueError on fstat() failure. diff -r 057a8bd043ea -r 42cf963e3ab1 Lib/test/test_signal.py --- a/Lib/test/test_signal.py Mon Jul 21 16:23:51 2014 +0200 +++ b/Lib/test/test_signal.py Mon Jul 21 16:28:54 2014 +0200 @@ -252,14 +252,14 @@ 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 -r 057a8bd043ea -r 42cf963e3ab1 Misc/NEWS --- a/Misc/NEWS Mon Jul 21 16:23:51 2014 +0200 +++ b/Misc/NEWS Mon Jul 21 16:28:54 2014 +0200 @@ -108,6 +108,9 @@ 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 -r 057a8bd043ea -r 42cf963e3ab1 Modules/signalmodule.c --- a/Modules/signalmodule.c Mon Jul 21 16:23:51 2014 +0200 +++ b/Modules/signalmodule.c Mon Jul 21 16:28:54 2014 +0200 @@ -437,12 +437,20 @@ 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); } /victor.stinner@gmail.com