From patchwork Thu Jan 23 08:27:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 313476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 73BBB2C0092 for ; Thu, 23 Jan 2014 19:31:11 +1100 (EST) Received: from localhost ([::1]:39509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Fgr-00072n-C9 for incoming@patchwork.ozlabs.org; Thu, 23 Jan 2014 03:31:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Fdv-0002Kr-Fj for qemu-devel@nongnu.org; Thu, 23 Jan 2014 03:28:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6Fdm-0000Bp-Ep for qemu-devel@nongnu.org; Thu, 23 Jan 2014 03:28:07 -0500 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:41601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Fdl-0000BB-Qc for qemu-devel@nongnu.org; Thu, 23 Jan 2014 03:27:58 -0500 Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 23 Jan 2014 13:57:55 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp04.in.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 23 Jan 2014 13:57:52 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 64F181258053 for ; Thu, 23 Jan 2014 13:59:32 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s0N8Rpug50397380 for ; Thu, 23 Jan 2014 13:57:51 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s0N8RpcY020643 for ; Thu, 23 Jan 2014 13:57:51 +0530 Received: from localhost.cn.ibm.com ([9.115.122.232]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s0N8RjXn020467; Thu, 23 Jan 2014 13:57:50 +0530 From: Lei Li To: qemu-devel@nongnu.org Date: Thu, 23 Jan 2014 16:27:40 +0800 Message-Id: <1390465663-17650-3-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1390465663-17650-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1390465663-17650-1-git-send-email-lilei@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14012308-5564-0000-0000-00000BAC3C65 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.4 Cc: mohan@in.ibm.com, Lei Li , pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 2/5] qemu-bridge-helper: replace send_fd with qemu_send_with_fd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Lei Li --- Makefile | 2 +- qemu-bridge-helper.c | 31 +++---------------------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index bdff4e4..6850f35 100644 --- a/Makefile +++ b/Makefile @@ -195,7 +195,7 @@ qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a qemu-io$(EXESUF): qemu-io.o $(block-obj-y) libqemuutil.a libqemustub.a -qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o +qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o libqemuutil.a fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 6a0974e..8303b6b 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -40,6 +40,7 @@ #endif #include "qemu/queue.h" +#include "qemu/fd-exchange.h" #include "net/tap-linux.h" @@ -174,33 +175,6 @@ static void prep_ifreq(struct ifreq *ifr, const char *ifname) snprintf(ifr->ifr_name, IFNAMSIZ, "%s", ifname); } -static int send_fd(int c, int fd) -{ - char msgbuf[CMSG_SPACE(sizeof(fd))]; - struct msghdr msg = { - .msg_control = msgbuf, - .msg_controllen = sizeof(msgbuf), - }; - struct cmsghdr *cmsg; - struct iovec iov; - char req[1] = { 0x00 }; - - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); - msg.msg_controllen = cmsg->cmsg_len; - - iov.iov_base = req; - iov.iov_len = sizeof(req); - - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd)); - - return sendmsg(c, &msg, 0); -} - #ifdef CONFIG_LIBCAP static int drop_privileges(void) { @@ -239,6 +213,7 @@ int main(int argc, char **argv) ACLList acl_list; int access_allowed, access_denied; int ret = EXIT_SUCCESS; + char req[1] = { 0x00 }; #ifdef CONFIG_LIBCAP /* if we're run from an suid binary, immediately drop privileges preserving @@ -424,7 +399,7 @@ int main(int argc, char **argv) } /* write fd to the domain socket */ - if (send_fd(unixfd, fd) == -1) { + if (qemu_send_with_fd(unixfd, fd, &req, sizeof(req)) == -1) { fprintf(stderr, "failed to write fd to unix socket: %s\n", strerror(errno)); ret = EXIT_FAILURE;