[Python-checkins] CVS: python/dist/src/Lib tempfile.py,1.37,1.38
Neil Schemenauer
nascheme@users.sourceforge.net
Sun, 24 Mar 2002 14:21:50 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv5994/Lib
Modified Files:
tempfile.py
Log Message:
If possible, set FD_CLOEXEC flag on file descriptors opened using
TemporaryFile. This flag causes the fd to be closed on exec().
Index: tempfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/tempfile.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** tempfile.py 30 Jan 2002 09:11:42 -0000 1.37
--- tempfile.py 24 Mar 2002 22:21:48 -0000 1.38
***************
*** 181,184 ****
--- 181,195 ----
return a
+ try:
+ import fcntl as _fcntl
+ def _set_cloexec(fd, flag=_fcntl.FD_CLOEXEC):
+ flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
+ if flags >= 0:
+ # flags read successfully, modify
+ flags |= flag
+ _fcntl.fcntl(fd, _fcntl.F_SETFD, flags)
+ except (ImportError, AttributeError):
+ def _set_cloexec(fd):
+ pass
def TemporaryFile(mode='w+b', bufsize=-1, suffix=""):
***************
*** 188,191 ****
--- 199,203 ----
# Unix -- be very careful
fd = os.open(name, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700)
+ _set_cloexec(fd)
try:
os.unlink(name)