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 benjamin.peterson
Recipients Dima.Tisnek, benjamin.peterson, python-dev
Date 2014-04-10.22:55:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397170530.18620.105191245.72C0A391@webmail.messagingengine.com>
In-reply-to <1397152010.99.0.0751502542298.issue21191@psf.upfronthosting.co.za>
Content
On Thu, Apr 10, 2014, at 10:46, Dima Tisnek wrote:
> 
> Dima Tisnek added the comment:
> 
> 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.

I meant once you manage to get fdopen to succeed, the fd has basically
been consumed.

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

I realize.

> 
> Perhaps if it's too hard to implement properly, it's better to leave this
> issue as won't fix / technical limitation?

I mean if you'd prefer for it to just be inconsistent in 2.x...
History
Date User Action Args
2014-04-10 22:55:33benjamin.petersonsetrecipients: + benjamin.peterson, python-dev, Dima.Tisnek
2014-04-10 22:55:33benjamin.petersonlinkissue21191 messages
2014-04-10 22:55:33benjamin.petersoncreate