From patchwork Fri Jun 8 14:53:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Bryant X-Patchwork-Id: 163792 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 323D7B6EF3 for ; Sat, 9 Jun 2012 01:27:50 +1000 (EST) Received: from localhost ([::1]:48740 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sd16K-0007ZM-1j for incoming@patchwork.ozlabs.org; Fri, 08 Jun 2012 11:27:48 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sd15i-00060s-82 for qemu-devel@nongnu.org; Fri, 08 Jun 2012 11:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sd15b-0003j5-T9 for qemu-devel@nongnu.org; Fri, 08 Jun 2012 11:27:09 -0400 Received: from cpe-174-097-227-101.nc.res.rr.com ([174.97.227.101]:54161 helo=localhost.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sd15b-0003iq-Mt for qemu-devel@nongnu.org; Fri, 08 Jun 2012 11:27:03 -0400 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.14.5/8.14.5) with ESMTP id q58BQtXF001079; Fri, 8 Jun 2012 07:26:59 -0400 Received: (from corey@localhost) by localhost.localdomain (8.14.5/8.14.5/Submit) id q58Es0jF026322; Fri, 8 Jun 2012 10:54:00 -0400 From: Corey Bryant To: qemu-devel@nongnu.org Date: Fri, 8 Jun 2012 10:53:55 -0400 Message-Id: <1339167236-26287-4-git-send-email-coreyb@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.2 In-Reply-To: <1339167236-26287-1-git-send-email-coreyb@linux.vnet.ibm.com> References: <1339167236-26287-1-git-send-email-coreyb@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 174.97.227.101 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, libvir-list@redhat.com, Corey Bryant , eblake@redhat.com Subject: [Qemu-devel] [PATCH v2 3/4] osdep: Enable qemu_open to dup pre-opened 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 This patch adds support to qemu_open to dup(X) a pre-opened file descriptor if the filename is of the format /dev/fd/X. This can be used when QEMU is restricted from opening files, and the management application opens files on QEMU's behalf. v2: -Get rid of file_open and move dup code to qemu_open (kwolf@redhat.com) -Use strtol wrapper instead of atoi (kwolf@redhat.com) Signed-off-by: Corey Bryant --- osdep.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/osdep.c b/osdep.c index 3e6bada..c17cdcb 100644 --- a/osdep.c +++ b/osdep.c @@ -82,6 +82,19 @@ int qemu_open(const char *name, int flags, ...) int ret; int mode = 0; +#ifndef _WIN32 + const char *p; + + /* Attempt dup of fd for pre-opened file */ + if (strstart(name, "/dev/fd/", &p)) { + ret = qemu_parse_fd(p); + if (ret == -1) { + return -1; + } + return dup(ret); + } +#endif + if (flags & O_CREAT) { va_list ap;