From patchwork Sat Mar 3 07:57:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ronnie sahlberg X-Patchwork-Id: 144411 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 9D5C1B6F9F for ; Sat, 3 Mar 2012 18:57:38 +1100 (EST) Received: from localhost ([::1]:51893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3jqS-0002PC-Ef for incoming@patchwork.ozlabs.org; Sat, 03 Mar 2012 02:57:36 -0500 Received: from eggs.gnu.org ([208.118.235.92]:39165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3jqI-0002P1-7S for qemu-devel@nongnu.org; Sat, 03 Mar 2012 02:57:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S3jqC-0001Vh-L9 for qemu-devel@nongnu.org; Sat, 03 Mar 2012 02:57:25 -0500 Received: from mail-pw0-f45.google.com ([209.85.160.45]:34508) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3jqC-0001Uj-CX for qemu-devel@nongnu.org; Sat, 03 Mar 2012 02:57:20 -0500 Received: by mail-pw0-f45.google.com with SMTP id uo5so2133823pbc.4 for ; Fri, 02 Mar 2012 23:57:19 -0800 (PST) Received-SPF: pass (google.com: domain of ronniesahlberg@gmail.com designates 10.68.233.227 as permitted sender) client-ip=10.68.233.227; Authentication-Results: mr.google.com; spf=pass (google.com: domain of ronniesahlberg@gmail.com designates 10.68.233.227 as permitted sender) smtp.mail=ronniesahlberg@gmail.com; dkim=pass header.i=ronniesahlberg@gmail.com Received: from mr.google.com ([10.68.233.227]) by 10.68.233.227 with SMTP id tz3mr15894578pbc.38.1330761439462 (num_hops = 1); Fri, 02 Mar 2012 23:57:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=fyC+RHKiz07M4o+M0W20sEi901++PJl/YOrF/BNJtnA=; b=z/XUJ3V1XdNiVYG5Wyngq8RMuAWxBEb+bDsnwyQbNi12arBu+GJIl927HLYe0ce5HM pQLMEs+EXgY601Ymmirptzhv3G5lXPPEw8hJ2m8SqWX1arjXINNCUpxW/soTGIpitHgh CtZ0/vD7iLDAr8dDNWiPHzYEQYRrQBhyf1z1ufcUS12KbvkiXEZis86BUWLz2dtQF1hF Q1Fh7I5RZfQy1G8ySNl5WPXWYfeNGHdhd1YLjpTMIZoYcLMFG/3h/hM+/T/VOjMPAOdl nl15/262q3FW/Tx0LJCsn35Fu59zQKl4DcVxjhwi0tMGcBBboSal17lwhcFEUxHD368r 8Ziw== Received: by 10.68.233.227 with SMTP id tz3mr13454626pbc.38.1330761439379; Fri, 02 Mar 2012 23:57:19 -0800 (PST) Received: from ronniesahlberg@gmail.com (CPE-60-229-38-244.lns7.ken.bigpond.net.au. [60.229.38.244]) by mx.google.com with ESMTPS id b6sm7207040pbf.32.2012.03.02.23.57.15 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 02 Mar 2012 23:57:18 -0800 (PST) Received: by ronniesahlberg@gmail.com (sSMTP sendmail emulation); Sat, 03 Mar 2012 18:57:12 +1100 From: Ronnie Sahlberg To: qemu-devel@nongnu.org, kwolf@redhat.com Date: Sat, 3 Mar 2012 18:57:01 +1100 Message-Id: <1330761421-17379-2-git-send-email-ronniesahlberg@gmail.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1330761421-17379-1-git-send-email-ronniesahlberg@gmail.com> References: <1330761421-17379-1-git-send-email-ronniesahlberg@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: Ronnie Sahlberg Subject: [Qemu-devel] [PATCH] READCONFIG: allow /dev/fd/ the file to use for --readconfig 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 On many platforms /dev/fd/ is used to refer to open filedescriptor of the running process. If we fail to open the provided filename and if the filename starts with '/dev/fd/' then assume this is a platform which do not support these special files. In that case read out the descriptor value from the provided string and fdopen it. This allows to use /dev/fd/ syntax on all platforms, those that do provide this indeface in /dev and an emulation of this for the platforms that do not provide /dev/fd Signed-off-by: Ronnie Sahlberg --- qemu-config.c | 16 +++++++++++++++- qemu-options.hx | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 7d9da78..96e7497 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -814,9 +814,23 @@ out: int qemu_read_config_file(const char *filename) { - FILE *f = fopen(filename, "r"); + FILE *f; int ret; + f = fopen(filename, "r"); + + if (f == NULL && !strncmp(filename, "/dev/fd/", 8)) { + int fd; + char *ptr = NULL; + + errno = 0; + fd = strtol(filename + 8, &ptr, 10); + if (errno != 0 || ptr == filename + 8 || *ptr != '\0') { + return -EINVAL; + } + f = fdopen(fd, "r"); + } + if (f == NULL) { return -errno; } diff --git a/qemu-options.hx b/qemu-options.hx index b129996..c70c6e7 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2650,7 +2650,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 '/dev/fd/' as filename +to read from an existing, inherited, filedesriptor. ETEXI DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, "-writeconfig \n"