On Wed, Mar 09, 2016 at 07:04:53PM +0100, Paolo Bonzini wrote:
> 
> 
> On 09/03/2016 18:28, Daniel P. Berrange wrote:
> > +static bool qemu_is_socket(int fd)
> > +{
> > +    int optval = 0;
> > +    socklen_t optlen;
> > +    optlen = sizeof(optval);
> > +    return getsockopt(fd, SOL_SOCKET, SO_TYPE,
> > +                      (char *)&optval, &optlen) == 0;
> 
> I think it's possible for a socket (which is actually a HANDLE) and a
> file descriptor with the same numeric value to exist at the same time.
> It's unlikely but it cannot be ruled out.

Aieee, nice one realizing that problem !

> gnulib does this getsockopt (or at least could plausibly do it, I didn't
> check :)) because it opens a libc file descriptor for every socket.
> However, this only breaks ioctl and close and patch 18; neither ioctl
> nor close's errors are ever checked in QEMU.
> Doing the libc file descriptor in wrapping makes the select and poll
> wrappers much more complex.  gnulib in fact even makes them work on
> files, consoles, etc. besides pipes to provide a fuller POSIX layer.  In
> my opinion this is beyond QEMU's scope and not really in line with
> QEMU's attempts to use Win32 natively whenever applicable (e.g. in
> qemu-char.c and block/raw-win32.c).
> 
> However, I'm okay with the other wrapping that you do in this patch.
> Being able to drop socket_error() is a big improvement.

Yep, so I've removed the wrapping of close/ioctl, and in their place
I'm wrapping closesocket/ioctlsocket to address errno/socket_error
handling in those.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

Reply via email to