Benjamin Peterson added the comment:

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...

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21191>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to