-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Bruno Haible on 8/22/2009 3:39 PM:
> Hi,
>
> Here's the proposed module for function 'accept4'.
>
> It does not define the macro SOCK_CLOEXEC. I think this macro should be
> replaced by a separate module, that would then also influence socket(),
> socketpair() - and what about connect()?
socket and socketpair both (need to) honor SOCK_CLOEXEC; but connect does
not create a new fd (it just modifies an existing one) so it doesn't need
any change.
> nfd = _open_osfhandle ((long) new_handle,
> O_NOINHERIT | (flags & (O_TEXT | O_BINARY)));
> if (nfd < 0)
> {
> int saved_errno = errno;
> close (fd);
> errno = saved_errno;
> return -1;
> }
>
> close (fd);
> return nfd;
This means that nfd > fd, so there is a gap in the fd sequence which is
unexpected per POSIX rules. Is it worth the hassle of using
dup2(nfd,fd),close(fd) instead of close(fd)?
> if (flags & SOCK_CLOEXEC)
> {
> int fcntl_flags;
>
> if ((fcntl_flags = fcntl (fd, F_GETFD, 0)) < 0
> || fcntl (fd, F_SETFD, fcntl_flags | FD_CLOEXEC) < 0)
Success for F_SETFD is like F_SETFL - you must compare against explicit -1.
Otherwise, looks sane to me. Do you have a test case in mind?
- --
Don't work too hard, make some time for fun as well!
Eric Blake [email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkqQrigACgkQ84KuGfSFAYCTxgCcD66ZPeAuT+x3Chag/LRP6ZOn
YhIAoI1jr91zmRgeqrosAFHElwdyJhQ1
=SbKS
-----END PGP SIGNATURE-----