]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #22018: signal.set_wakeup_fd() now raises an OSError instead of a
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 21 Jul 2014 14:28:54 +0000 (16:28 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 21 Jul 2014 14:28:54 +0000 (16:28 +0200)
ValueError on fstat() failure.

Lib/test/test_signal.py
Misc/NEWS
Modules/signalmodule.c

index de3b40f746a1510adfccd76dddfbdb582480a3f4..e40dfb5658cfeceab4c73ab669055f2321620d8f 100644 (file)
@@ -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)
index 5a8d162c74427068837fe1366569929c71499eab..cd4ad679b8cf9f6126bdba44573a166a195285e3 100644 (file)
--- 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.
 
index cf4ba6123ab2c91b3b46ab267ac2a160856ca84d..c4f0121644412224c47118a024491c4b9a444ecf 100644 (file)
@@ -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);
 }