]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #12105: Add O_CLOEXEC to the os module.
authorCharles-François Natali <neologix@free.fr>
Sun, 22 May 2011 18:42:32 +0000 (20:42 +0200)
committerCharles-François Natali <neologix@free.fr>
Sun, 22 May 2011 18:42:32 +0000 (20:42 +0200)
Doc/library/os.rst
Lib/test/test_posix.py
Misc/NEWS
Modules/posixmodule.c

index 86f587fd2b9d9960a5f75782aeee17c1589f688a..6ef6d9d25abe93c07dd000c4a602a918cac9aebb 100644 (file)
@@ -1298,6 +1298,7 @@ or `the MSDN <http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Window
           O_NOCTTY
           O_SHLOCK
           O_EXLOCK
+          O_CLOEXEC
 
    These constants are only available on Unix.
 
index 0e9ac75172c402bd4221b81bb2b2b3e7a68a8bc2..9c2cac394fbdf2c9aa7e287b29a3e9cd648a6424 100644 (file)
@@ -9,6 +9,7 @@ import errno
 import sys
 import time
 import os
+import fcntl
 import pwd
 import shutil
 import stat
@@ -307,6 +308,12 @@ class PosixTester(unittest.TestCase):
                 fp1.close()
                 fp2.close()
 
+    @unittest.skipUnless(hasattr(os, 'O_CLOEXEC'), "needs os.O_CLOEXEC")
+    def test_oscloexec(self):
+        fd = os.open(support.TESTFN, os.O_RDONLY|os.O_CLOEXEC)
+        self.addCleanup(os.close, fd)
+        self.assertTrue(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC)
+
     def test_osexlock(self):
         if hasattr(posix, "O_EXLOCK"):
             fd = os.open(support.TESTFN,
index b34165380c432ee61900b5abf2aacffb0be1c58a..963ff893daa3167fcf9664c345a190c69d51f050 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -153,6 +153,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #12105: Add O_CLOEXEC to the os module.
+
 - Issue #12079: Decimal('Infinity').fma(Decimal('0'), (3.91224318126786e+19+0j))
   now raises TypeError (reflecting the invalid type of the 3rd argument) rather
   than Decimal.InvalidOperation.
index 396243e0a57ee58268173ff32d052d4314e2a5b5..9c19ed0433aa6e64a7f30c249080d10d97506b93 100644 (file)
@@ -9783,6 +9783,9 @@ all_ins(PyObject *d)
 #ifdef PRIO_USER
     if (ins(d, "PRIO_USER", (long)PRIO_USER)) return -1;
 #endif
+#ifdef O_CLOEXEC
+    if (ins(d, "O_CLOEXEC", (long)O_CLOEXEC)) return -1;
+#endif
 /* posix - constants for *at functions */
 #ifdef AT_SYMLINK_NOFOLLOW
         if (ins(d, "AT_SYMLINK_NOFOLLOW", (long)AT_SYMLINK_NOFOLLOW)) return -1;