From patchwork Tue Sep 7 12:31:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john cooper X-Patchwork-Id: 64004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5A3A8B6F06 for ; Tue, 7 Sep 2010 22:34:08 +1000 (EST) Received: from localhost ([127.0.0.1]:40649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsxNF-0004R0-F3 for incoming@patchwork.ozlabs.org; Tue, 07 Sep 2010 08:34:05 -0400 Received: from [140.186.70.92] (port=42737 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsxLu-0004Pn-Eh for qemu-devel@nongnu.org; Tue, 07 Sep 2010 08:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OsxLt-0004Li-3M for qemu-devel@nongnu.org; Tue, 07 Sep 2010 08:32:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6772) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OsxLs-0004Le-Rb for qemu-devel@nongnu.org; Tue, 07 Sep 2010 08:32:41 -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 o87CWeVk002335 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 7 Sep 2010 08:32:40 -0400 Received: from anvil.naka.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o87CWY8t019056; Tue, 7 Sep 2010 08:32:37 -0400 Message-ID: <4C8630AA.5030908@redhat.com> Date: Tue, 07 Sep 2010 08:31:38 -0400 From: john cooper User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: qemu-devel@nongnu.org X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: john cooper Subject: [Qemu-devel] [PATCH 4/4] cpu model corrections/updates: add verbose config file handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Failure by qemu to open a default config file isn't cause to error exit -- it just quietly continues on. After puzzling issues with otherwise opaque config file locations and startup handling numerous times, some help from qemu seemed justified. In the case of a "?" pseudo filename arg to -readconfig, verbose open of all config files will be enabled. Normal handling of config files is otherwise unaffected by this option. Signed-off-by: john cooper diff --git a/qemu-config.c b/qemu-config.c index 1efdbec..805fcc6 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -534,21 +534,31 @@ out: return res; } -int qemu_read_config_file(const char *filename) +/* attempt to open and parse config file, report problems if vflag + */ +int qemu_read_config_file(const char *filename, int vflag) { FILE *f = fopen(filename, "r"); - int ret; + int rv = 0; + const char *err; if (f == NULL) { - return -errno; + rv = -errno; + err = "open"; } - - ret = qemu_config_parse(f, vm_config_groups, filename); - fclose(f); - - if (ret == 0) { - return 0; - } else { - return -EINVAL; + else if (qemu_config_parse(f, vm_config_groups, filename) != 0) { + rv = -EINVAL; + err = "parse"; + } + else if (vflag) { + fprintf(stderr, "parsed config file %s\n", filename); + } + if (f) { + fclose(f); + } + if (rv && vflag) { + fprintf(stderr, "can't %s config file %s: %s\n", + err, filename, strerror(-rv)); } + return rv; } diff --git a/qemu-config.h b/qemu-config.h index 533a049..897fbce 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -13,6 +13,6 @@ void qemu_add_globals(void); void qemu_config_write(FILE *fp); int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname); -int qemu_read_config_file(const char *filename); +int qemu_read_config_file(const char *filename, int vflag); #endif /* QEMU_CONFIG_H */ diff --git a/vl.c b/vl.c index fd491ba..d192b51 100644 --- a/vl.c +++ b/vl.c @@ -1822,6 +1822,7 @@ int main(int argc, char **argv, char **envp) const char *incoming = NULL; int show_vnc_port = 0; int defconfig = 1; + int defconfig_verbose = 0; atexit(qemu_run_exit_notifiers); error_set_progname(argv[0]); @@ -1875,6 +1876,11 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_nodefconfig: defconfig=0; break; + case QEMU_OPTION_readconfig: + /* pseudo filename "?" enables verbose config file handling */ + if (!strcmp(optarg, "?")) + defconfig_verbose = 1; + break; } } } @@ -1882,12 +1888,13 @@ int main(int argc, char **argv, char **envp) if (defconfig) { int ret; - ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf"); + ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf", + defconfig_verbose); if (ret < 0 && ret != -ENOENT) { exit(1); } - ret = qemu_read_config_file(arch_config_name); + ret = qemu_read_config_file(arch_config_name, defconfig_verbose); if (ret < 0 && ret != -ENOENT) { exit(1); } @@ -2596,15 +2603,10 @@ int main(int argc, char **argv, char **envp) xen_mode = XEN_ATTACH; break; case QEMU_OPTION_readconfig: - { - int ret = qemu_read_config_file(optarg); - if (ret < 0) { - fprintf(stderr, "read config %s: %s\n", optarg, - strerror(-ret)); + if (strcmp(optarg, "?") && + qemu_read_config_file(optarg, defconfig_verbose) < 0) exit(1); - } - break; - } + break; case QEMU_OPTION_writeconfig: { FILE *fp;