From 7530e8cdd506ecec1f4ad3bbd55f94de5a6d63ac Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 26 Oct 2020 14:21:53 +0000 Subject: Separate and expose ancil_recv_fd/ancil_send_fd The goal is to make late channel creation easy, as opposed to textclient which always creates a new channel at start time. This commit also moves posixishard.h inclusions as late as possible. --- src/libunixonacid/textclient_start.c | 65 ++++-------------------------------- 1 file changed, 7 insertions(+), 58 deletions(-) (limited to 'src/libunixonacid/textclient_start.c') diff --git a/src/libunixonacid/textclient_start.c b/src/libunixonacid/textclient_start.c index 8eb8b13..3074ae3 100644 --- a/src/libunixonacid/textclient_start.c +++ b/src/libunixonacid/textclient_start.c @@ -1,26 +1,18 @@ /* ISC license. */ -#include -#include - #include #include #include -#include -#include #include +#include #include #include #include +#include #include #include - -union aligner_u -{ - struct cmsghdr cmsghdr ; - int i ; -} ; +#include static int getfd (void *p) { @@ -29,56 +21,13 @@ static int getfd (void *p) static ssize_t get (void *p) { - static int const awesomeflags = -#ifdef SKALIBS_HASMSGDONTWAIT - MSG_DONTWAIT -#else - 0 -#endif - | -#ifdef SKALIBS_HASCMSGCLOEXEC - MSG_CMSG_CLOEXEC -#else - 0 -#endif - ; - struct cmsghdr *c ; int *fd = p ; - ssize_t r ; - union aligner_u ancilbuf[1 + (CMSG_SPACE(sizeof(int)) - 1) / sizeof(union aligner_u)] ; - char ch ; - struct iovec v = { .iov_base = &ch, .iov_len = 1 } ; - struct msghdr msghdr = - { - .msg_name = 0, - .msg_namelen = 0, - .msg_iov = &v, - .msg_iovlen = 1, - .msg_flags = 0, - .msg_control = ancilbuf, - .msg_controllen = CMSG_SPACE(sizeof(int)) - } ; - do r = recvmsg(fd[0], &msghdr, awesomeflags) ; - while (r < 0 && errno == EINTR) ; - if (r <= 0) return sanitize_read(r) ; - c = CMSG_FIRSTHDR(&msghdr) ; - if (ch != '|' - || !c - || c->cmsg_level != SOL_SOCKET - || c->cmsg_type != SCM_RIGHTS - || (size_t)(c->cmsg_len - (CMSG_DATA(c) - (unsigned char *)c)) != sizeof(int)) return (errno = EPROTO, -1) ; -#ifndef SKALIBS_HASCMSGCLOEXEC - if (coe(*(int *)CMSG_DATA(c)) < 0) - { - fd_close(*(int *)CMSG_DATA(c)) ; - return -1 ; - } -#endif - fd[1] = *(int *)CMSG_DATA(c) ; + int r = ancil_recv_fd(fd[0], '|') ; + if (r < 0) return error_isagain(errno) ? (errno = 0, 0) : r ; + fd[1] = r ; return 1 ; } - - + int textclient_start (textclient_t *a, char const *path, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) { struct iovec v ; -- cgit v1.2.3