This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dima.Tisnek
Recipients Dima.Tisnek, benjamin.peterson, python-dev
Date 2014-04-10.17:46:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397152010.99.0.0751502542298.issue21191@psf.upfronthosting.co.za>
In-reply-to
Content
I'm not sure if you are referring to Python's C-level fdopen or GNU libc fdopen.

GNU libc fdopen does not consume file descriptor on error:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>


int main(int argc, char** argv)
{
    int fd = -1;
    int rv = 0;
    FILE* fh = NULL;
    if (argc<3) return 1;

    errno = 0;
    fd = open(argv[1], O_RDONLY);
    printf("got fd %d errno %d text %s\n", fd, errno, strerror(errno));

    errno = 0;
    fh = fdopen(fd, argv[2]);
    printf("got fh %x errno %d text %s\n", fh, errno, strerror(errno));

    errno = 0;
    rv = close(fd);
    printf("got rv %d errno %d text %s\n", rv, errno, strerror(errno));
}

[dima@bmg ~]$ ./a.out /etc/passwd w
got fd 4 errno 0 text Success
got fh 0 errno 22 text Invalid argument
got rv 0 errno 0 text Success

To be fair, GNU libc fdopen doesn't consider it an error to use a file descriptor that refers to a directory, which is the crux of this bug.

Anyhow, point is the semantics change your patch brings in sets Python 2.7+ in contrast with both Python 3.x and GNU libc. 

Perhaps if it's too hard to implement properly, it's better to leave this issue as won't fix / technical limitation?
History
Date User Action Args
2014-04-10 17:46:51Dima.Tisneksetrecipients: + Dima.Tisnek, benjamin.peterson, python-dev
2014-04-10 17:46:50Dima.Tisneksetmessageid: <1397152010.99.0.0751502542298.issue21191@psf.upfronthosting.co.za>
2014-04-10 17:46:50Dima.Tisneklinkissue21191 messages
2014-04-10 17:46:50Dima.Tisnekcreate