From 715a664ac4ca3b9e44ffbc0ca41ecd91fbe96656 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 14 Oct 2009 10:39:28 +0200 Subject: [PATCH] QemuOpts: command line switches for the config file. 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 Signed-off-by: Anthony Liguori --- qemu-options.hx | 5 +++++ vl.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index 792219175a..b65fd74f32 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1915,3 +1915,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 402e78d987..bf91ee15d4 100644 --- a/vl.c +++ b/vl.c @@ -5364,6 +5364,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; + } } } }