From 1e045b183104df770e232e756986bf301c87e9ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Fran=C3=A7ois=20Natali?= Date: Sun, 22 May 2011 20:42:32 +0200 Subject: [PATCH] Issue #12105: Add O_CLOEXEC to the os module. --- Doc/library/os.rst | 1 + Lib/test/test_posix.py | 7 +++++++ Misc/NEWS | 2 ++ Modules/posixmodule.c | 3 +++ 4 files changed, 13 insertions(+) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 86f587fd2b9..6ef6d9d25ab 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1298,6 +1298,7 @@ or `the MSDN `_ on Window O_NOCTTY O_SHLOCK O_EXLOCK + O_CLOEXEC These constants are only available on Unix. diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 0e9ac75172c..9c2cac394fb 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -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, diff --git a/Misc/NEWS b/Misc/NEWS index b34165380c4..963ff893daa 100644 --- 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. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 396243e0a57..9c19ed0433a 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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;