From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjQJ9-0006kn-G1 for qemu-devel@nongnu.org; Thu, 21 Nov 2013 04:12:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VjQJ0-0003QI-JC for qemu-devel@nongnu.org; Thu, 21 Nov 2013 04:12:19 -0500 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:47776) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjQJ0-0003P6-0G for qemu-devel@nongnu.org; Thu, 21 Nov 2013 04:12:10 -0500 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 21 Nov 2013 14:42:08 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 5D2411258054 for ; Thu, 21 Nov 2013 14:43:00 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rAL9Bx4155574536 for ; Thu, 21 Nov 2013 14:41:59 +0530 Received: from d28av03.in.ibm.com (localhost [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rAL9C4LY030123 for ; Thu, 21 Nov 2013 14:42:05 +0530 From: Lei Li Date: Thu, 21 Nov 2013 17:11:29 +0800 Message-Id: <1385025100-3191-7-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1385025100-3191-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1385025100-3191-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 06/17] migration-local: add send_pipefd() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aarcange@redhat.com, Lei Li , quintela@redhat.com, mdroth@linux.vnet.ibm.com, mrhines@linux.vnet.ibm.com, aliguori@amazon.com, lagarcia@br.ibm.com, pbonzini@redhat.com, rcj@linux.vnet.ibm.com This patch adds send_pipefd() to pass the pipe file descriptor to destination process. Signed-off-by: Lei Li --- migration-local.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/migration-local.c b/migration-local.c index 28da05b..f4265a1 100644 --- a/migration-local.c +++ b/migration-local.c @@ -165,3 +165,56 @@ fail: g_free(s); return NULL; } + + +/* + * Pass a pipe file descriptor to another process. + * + * Return negative value If pipefd < 0. Return 0 on + * success. + * + */ +static int send_pipefd(int sockfd, int pipefd) +{ + struct msghdr msg; + struct iovec iov[1]; + ssize_t ret; + + union { + struct cmsghdr cm; + char control[CMSG_SPACE(sizeof(int))]; + } control_un; + struct cmsghdr *cmptr; + char req[1] = { 0x01 }; + + if (pipefd < 0) { + msg.msg_control = NULL; + msg.msg_controllen = 0; + /* Negative status means error */ + req[0] = pipefd; + } else { + msg.msg_control = control_un.control; + msg.msg_controllen = sizeof(control_un.control); + + cmptr = CMSG_FIRSTHDR(&msg); + cmptr->cmsg_len = CMSG_LEN(sizeof(int)); + cmptr->cmsg_level = SOL_SOCKET; + cmptr->cmsg_type = SCM_RIGHTS; + *((int *) CMSG_DATA(cmptr)) = pipefd; + + msg.msg_name = NULL; + msg.msg_namelen = 0; + + iov[0].iov_base = req; + iov[0].iov_len = sizeof(req); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + } + + ret = sendmsg(sockfd, &msg, 0); + if (ret <= 0) { + DPRINTF("sendmsg error: %s\n", strerror(errno)); + } + + return ret; +} -- 1.7.7.6