diff --git a/src/util/virfile.c b/src/util/virfile.c index f3108e99cf..9463833d31 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2445,9 +2445,7 @@ virFileOpenForked(const char *path, int openflags, mode_t mode, goto childerror; } - do { - ret = virSocketSendFD(pair[1], fd); - } while (ret < 0 && errno == EINTR); + ret = virSocketSendFD(pair[1], fd); if (ret < 0) { ret = -errno; diff --git a/src/util/virsocket.c b/src/util/virsocket.c index a7272a3ec9..01d84ee973 100644 --- a/src/util/virsocket.c +++ b/src/util/virsocket.c @@ -382,38 +382,16 @@ vir_socket(int domain, int type, int protocol) /* virSocketSendFD sends the file descriptor fd along the socket to a process calling virSocketRecvFD on the other end. - Return 0 on success, or -1 with errno set in case of error. + Return 1 on success, or -1 with errno set in case of error. */ int virSocketSendFD(int sock, int fd) { char byte = 0; - struct iovec iov; - struct msghdr msg = { 0 }; - struct cmsghdr *cmsg; - char buf[CMSG_SPACE(sizeof(fd))]; + int fds[] = { fd }; - /* send at least one char */ - iov.iov_base = &byte; - iov.iov_len = 1; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_name = NULL; - msg.msg_namelen = 0; - - msg.msg_control = buf; - msg.msg_controllen = sizeof(buf); - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); - /* Initialize the payload: */ - memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd)); - msg.msg_controllen = cmsg->cmsg_len; - - if (sendmsg(sock, &msg, 0) != iov.iov_len) - return -1; - return 0; + return virSocketSendMsgWithFDs(sock, &byte, sizeof(byte), + fds, G_N_ELEMENTS(fds)); }