From f7544edcd32e602af1aae86714dc7c32350d5d7c Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 26 Feb 2021 12:08:16 -0500 Subject: qemu-config: add error propagation to qemu_config_parse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This enables some simplification of vl.c via error_fatal, and improves error messages. Before: $ ./qemu-system-x86_64 -readconfig . qemu-system-x86_64: error reading file qemu-system-x86_64: -readconfig .: read config .: Invalid argument $ /usr/libexec/qemu-kvm -readconfig foo qemu-kvm: -readconfig foo: read config foo: No such file or directory After: $ ./qemu-system-x86_64 -readconfig . qemu-system-x86_64: -readconfig .: Cannot read config file: Is a directory $ ./qemu-system-x86_64 -readconfig foo qemu-system-x86_64: -readconfig foo: Could not open 'foo': No such file or directory Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Markus Armbruster Message-Id: <20210226170816.231173-1-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'softmmu') diff --git a/softmmu/vl.c b/softmmu/vl.c index 7e8110bd6e..2f4958db2a 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2062,17 +2062,19 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) return 0; } -static int qemu_read_default_config_file(void) +static void qemu_read_default_config_file(Error **errp) { + ERRP_GUARD(); int ret; g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); - ret = qemu_read_config_file(file); - if (ret < 0 && ret != -ENOENT) { - return ret; + ret = qemu_read_config_file(file, errp); + if (ret < 0) { + if (ret == -ENOENT) { + error_free(*errp); + *errp = NULL; + } } - - return 0; } static int qemu_set_option(const char *str) @@ -2633,9 +2635,7 @@ void qemu_init(int argc, char **argv, char **envp) } if (userconfig) { - if (qemu_read_default_config_file() < 0) { - exit(1); - } + qemu_read_default_config_file(&error_fatal); } /* second pass of option parsing */ @@ -3323,15 +3323,8 @@ void qemu_init(int argc, char **argv, char **envp) qemu_plugin_opt_parse(optarg, &plugin_list); break; case QEMU_OPTION_readconfig: - { - int ret = qemu_read_config_file(optarg); - if (ret < 0) { - error_report("read config %s: %s", optarg, - strerror(-ret)); - exit(1); - } - break; - } + qemu_read_config_file(optarg, &error_fatal); + break; case QEMU_OPTION_spice: olist = qemu_find_opts_err("spice", NULL); if (!olist) { -- cgit v1.2.3