From patchwork Thu Jan 26 09:54:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: ronnie sahlberg X-Patchwork-Id: 137898 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6F1B01007D2 for ; Thu, 26 Jan 2012 20:54:35 +1100 (EST) Received: from localhost ([::1]:47282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqM2H-0001hh-7F for incoming@patchwork.ozlabs.org; Thu, 26 Jan 2012 04:54:29 -0500 Received: from eggs.gnu.org ([140.186.70.92]:52536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqM28-0001hc-F7 for qemu-devel@nongnu.org; Thu, 26 Jan 2012 04:54:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RqM20-0002ra-KQ for qemu-devel@nongnu.org; Thu, 26 Jan 2012 04:54:20 -0500 Received: from mail-tul01m020-f173.google.com ([209.85.214.173]:41764) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqM20-0002rQ-Fg for qemu-devel@nongnu.org; Thu, 26 Jan 2012 04:54:12 -0500 Received: by obbup16 with SMTP id up16so390109obb.4 for ; Thu, 26 Jan 2012 01:54:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=IZKsoDml1fRodoE2ailpWCDoOHud4idSsmqQ4IoOMuA=; b=ASpWrSfmK+WtXKZlwbTaF00NjmDv1Mf2y3Mbbmlp0juCKUkQl1WZhBrht+u9SvDEC5 oddRDBApjAStmTFrtcfG+pMvOscbUMKck4mn5Z+qttLFuX0xkDnGl7/0NEBx6vgsS7q0 hrSANiMyfTF/lvfDsLCfe5qPLnh09sdr3uLqk= MIME-Version: 1.0 Received: by 10.182.150.66 with SMTP id ug2mr1449319obb.68.1327571651526; Thu, 26 Jan 2012 01:54:11 -0800 (PST) Received: by 10.182.214.42 with HTTP; Thu, 26 Jan 2012 01:54:11 -0800 (PST) In-Reply-To: <4F211C9F.4030209@redhat.com> References: <1327140203-3165-1-git-send-email-ronniesahlberg@gmail.com> <1327140203-3165-2-git-send-email-ronniesahlberg@gmail.com> <4F1DA1D5.1010600@redhat.com> <4F20266F.20409@redhat.com> <4F211813.7060404@redhat.com> <4F211C9F.4030209@redhat.com> Date: Thu, 26 Jan 2012 20:54:11 +1100 Message-ID: From: ronnie sahlberg To: Kevin Wolf X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.173 Cc: Eric Blake , qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI 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 Ok so what about this You use a filename starting with "/proc/self/fd/" and you dont have a proc filesystem mounted? you are on your own! regards ronnie sahlberg On Thu, Jan 26, 2012 at 8:27 PM, Kevin Wolf wrote: > Am 26.01.2012 10:18, schrieb ronnie sahlberg: >> Kevin, >> >> Collissions are bad, but what about >> >> IF ! STRNCMP (filename, "/proc/self/fd/", 14)  THEN >>          fopen(filename, "r") >> ELSE >>         fdopen(atoi(filename+14), "r") >> FI >> >> modulo better validation for the atio() arguments. >> >> >> Probability of anyone using "/proc/self/fd/" as a prefix for normal >> files is very small. >> Small enough it will be justifiable to say "do that and you are on your own". ? > > Interesting idea. Maybe that could work. > > Kevin From 65aa496d77b839f1c48745fc5545e3e6772f724c Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Thu, 26 Jan 2012 20:47:40 +1100 Subject: [PATCH] READCONFIG: make /proc/self/fd/ a magic prefix to refer to a specific filedesriptor inherited from the parent. Signed-off-by: Ronnie Sahlberg --- qemu-config.c | 16 ++++++++++++++-- qemu-options.hx | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index b030205..9e709d4 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -770,8 +770,20 @@ out: int qemu_read_config_file(const char *filename) { - FILE *f = fopen(filename, "r"); - int ret; + FILE *f; + int ret, fd; + char *ptr = NULL; + + if (strncmp(filename, "/proc/self/fd/", 14)) { + f = fopen(filename, "r"); + } else { + errno = 0; + fd = strtol(filename + 14, &ptr, 10); + if (errno != 0 || ptr == filename + 14 || *ptr != '\0') { + return -EINVAL; + } + f = fdopen(fd, "r"); + } if (f == NULL) { return -errno; diff --git a/qemu-options.hx b/qemu-options.hx index 3a07ae8..e54af58 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2577,7 +2577,8 @@ DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, STEXI @item -readconfig @var{file} @findex -readconfig -Read device configuration from @var{file}. +Read device configuration from @var{file}. Use '/proc/self/fd/' as filename +to read from an existing, inherited, filedesriptor. ETEXI DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, "-writeconfig \n" -- 1.7.3.1