diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-12-20 23:02:38 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-12-20 23:02:38 +0000 |
commit | 7c925e3e76d239b8cca5a31ddd045aad10190e8a (patch) | |
tree | 4329ce609ffc3c95b2e495a0e5f8f5c7c3e458b6 /src | |
parent | db7f4d2c1ef70334af4cb8c1980f47d8a9f69249 (diff) | |
download | skalibs-7c925e3e76d239b8cca5a31ddd045aad10190e8a.tar.xz |
FreeBSD now chokes on tryancilautoclose ; tentative fix
Diffstat (limited to 'src')
-rw-r--r-- | src/sysdeps/tryancilautoclose.c | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/src/sysdeps/tryancilautoclose.c b/src/sysdeps/tryancilautoclose.c index 7b4a563..c58e3b8 100644 --- a/src/sysdeps/tryancilautoclose.c +++ b/src/sysdeps/tryancilautoclose.c @@ -3,11 +3,16 @@ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif + #ifndef _XPG4_2 # define _XPG4_2 #endif #include <sys/types.h> +#include <string.h> #include <unistd.h> #include <errno.h> #include <sys/socket.h> @@ -25,22 +30,20 @@ struct ancilbuf_s static int ancil_send_fd (int sock, int fd) { - struct msghdr msghdr ; - struct iovec nothing_ptr ; ancilbuf_t buf ; - struct cmsghdr *cmsg ; - char nothing = '!' ; - - nothing_ptr.iov_base = ¬hing ; - nothing_ptr.iov_len = 1 ; - msghdr.msg_name = 0 ; - msghdr.msg_namelen = 0 ; - msghdr.msg_iov = ¬hing_ptr ; - msghdr.msg_iovlen = 1 ; - msghdr.msg_flags = 0 ; - msghdr.msg_control = &buf ; - msghdr.msg_controllen = sizeof(ancilbuf_t) ; - cmsg = CMSG_FIRSTHDR(&msghdr) ; + char s[8] = "blahblah" ; + struct iovec v = { .iov_base = s, .iov_len = 8 } ; + struct msghdr msghdr = + { + .msg_name = 0, + .msg_namelen = 0, + .msg_iov = &v, + .msg_iovlen = 1, + .msg_flags = 0, + .msg_control = &buf, + .msg_controllen = sizeof(ancilbuf_t) + } ; + struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msghdr) ; cmsg->cmsg_len = msghdr.msg_controllen ; cmsg->cmsg_level = SOL_SOCKET ; cmsg->cmsg_type = SCM_RIGHTS ; @@ -50,27 +53,26 @@ static int ancil_send_fd (int sock, int fd) static int ancil_recv_fd (int sock) { - struct msghdr msghdr ; - struct iovec nothing_ptr ; ancilbuf_t buf ; - struct cmsghdr *cmsg ; - char nothing ; - - nothing_ptr.iov_base = ¬hing ; - nothing_ptr.iov_len = 1 ; - msghdr.msg_name = 0 ; - msghdr.msg_namelen = 0 ; - msghdr.msg_iov = ¬hing_ptr ; - msghdr.msg_iovlen = 1 ; - msghdr.msg_flags = 0 ; - msghdr.msg_control = &buf ; - msghdr.msg_controllen = sizeof(ancilbuf_t) ; - cmsg = CMSG_FIRSTHDR(&msghdr) ; + char s[8] ; + struct iovec v = { .iov_base = s, .iov_len = 8 } ; + struct msghdr msghdr = + { + .msg_name = 0, + .msg_namelen = 0, + .msg_iov = &v, + .msg_iovlen = 1, + .msg_flags = 0, + .msg_control = &buf, + .msg_controllen = sizeof(ancilbuf_t) + } ; + struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msghdr) ; cmsg->cmsg_len = msghdr.msg_controllen ; cmsg->cmsg_level = SOL_SOCKET ; cmsg->cmsg_type = SCM_RIGHTS ; *((int *)CMSG_DATA(cmsg)) = -1 ; - if (recvmsg(sock, &msghdr, 0) < 0) return -1 ; + if (recvmsg(sock, &msghdr, 0) != 8) return -1 ; + if (memcmp(s, "blahblah", 8)) return -1 ; return *((int *)CMSG_DATA(cmsg)) ; } |