skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 7c925e3e76d239b8cca5a31ddd045aad10190e8a
parent db7f4d2c1ef70334af4cb8c1980f47d8a9f69249
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Sat, 20 Dec 2014 23:02:38 +0000

 FreeBSD now chokes on tryancilautoclose ; tentative fix

Diffstat:
Msrc/sysdeps/tryancilautoclose.c | 64+++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 33 insertions(+), 31 deletions(-)

diff --git 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 = &nothing ; - nothing_ptr.iov_len = 1 ; - msghdr.msg_name = 0 ; - msghdr.msg_namelen = 0 ; - msghdr.msg_iov = &nothing_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 = &nothing ; - nothing_ptr.iov_len = 1 ; - msghdr.msg_name = 0 ; - msghdr.msg_namelen = 0 ; - msghdr.msg_iov = &nothing_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)) ; }