From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MxzOX-0006eY-Is for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxzOS-0006ch-2k for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:41 -0400 Received: from [199.232.76.173] (port=40703 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxzOR-0006cP-7x for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62703) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MxzOQ-000497-M6 for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:34 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9E8dXWX031333 for ; Wed, 14 Oct 2009 04:39:34 -0400 From: Gerd Hoffmann Date: Wed, 14 Oct 2009 10:39:28 +0200 Message-Id: <1255509568-10635-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1255509568-10635-1-git-send-email-kraxel@redhat.com> References: <1255509568-10635-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 4/4] QemuOpts: command line switches for the config file. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Adds -readconfig and -writeconfig command line switches to read/write QemuOpts from config file. In theory you should be able to do: qemu < machine config cmd line switches here > -writeconfig vm.cfg qemu -readconfig vm.cfg In practice it will not work. Not all command line switches are converted to QemuOpts, so you'll have to keep the not-yet converted ones on the second line. Also there might be bugs lurking which prevent even the converted ones from working correctly. Signed-off-by: Gerd Hoffmann --- qemu-options.hx | 5 +++++ vl.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index 3dd76b3..6cbf9e2 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1682,3 +1682,8 @@ DEF("semihosting", 0, QEMU_OPTION_semihosting, DEF("old-param", 0, QEMU_OPTION_old_param, "-old-param old param mode\n") #endif +DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, + "-readconfig \n") +DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, + "-writeconfig \n" + " read/write config file") diff --git a/vl.c b/vl.c index afe01af..ad902fe 100644 --- a/vl.c +++ b/vl.c @@ -5513,6 +5513,36 @@ int main(int argc, char **argv, char **envp) xen_mode = XEN_ATTACH; break; #endif + case QEMU_OPTION_readconfig: + { + FILE *fp; + fp = fopen(optarg, "r"); + if (fp == NULL) { + fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); + exit(1); + } + if (qemu_config_parse(fp) != 0) { + exit(1); + } + fclose(fp); + break; + } + case QEMU_OPTION_writeconfig: + { + FILE *fp; + if (strcmp(optarg, "-") == 0) { + fp = stdout; + } else { + fp = fopen(optarg, "w"); + if (fp == NULL) { + fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); + exit(1); + } + } + qemu_config_write(fp); + fclose(fp); + break; + } } } } -- 1.6.2.5