[Python-bugs-list] [ python-Bugs-821896 ] _set_cloexec of tempfile.py uses incorrect error handling

SourceForge.net noreply at sourceforge.net
Sat Oct 11 15:49:20 EDT 2003


Bugs item #821896, was opened at 2003-10-11 21:49
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=821896&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Per Cederqvist (ceder)
Assigned to: Nobody/Anonymous (nobody)
Summary: _set_cloexec of tempfile.py uses incorrect error handling

Initial Comment:
The _set_cloexec function of tempfile.py looks like
this on Unix-like platforms:

    def _set_cloexec(fd):
        flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
        if flags >= 0:
            # flags read successfully, modify
            flags |= _fcntl.FD_CLOEXEC
            _fcntl.fcntl(fd, _fcntl.F_SETFD, flags)

However, fcntl.fcntl() will never return a negative
value.  If an error occurs, it will instead raise an
exception:

>>> fcntl.fcntl(10, fcntl.F_GETFD, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 9] Bad file descriptor

(This was tested on Linux.)

I doubt that this will ever cause any problems, except
if somebody uses the code as an example and copies the
error to their own code.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=821896&group_id=5470



More information about the Python-bugs-list mailing list