From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NteRZ-0004Cz-WA for qemu-devel@nongnu.org; Mon, 22 Mar 2010 06:01:10 -0400 Received: from [199.232.76.173] (port=52951 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NteRZ-0004CI-EI for qemu-devel@nongnu.org; Mon, 22 Mar 2010 06:01:09 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NteRU-00087f-D9 for qemu-devel@nongnu.org; Mon, 22 Mar 2010 06:01:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22990) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NteRT-00087R-V2 for qemu-devel@nongnu.org; Mon, 22 Mar 2010 06:01:04 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2MA12u0030982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 22 Mar 2010 06:01:02 -0400 From: Kevin Wolf Date: Mon, 22 Mar 2010 11:00:18 +0100 Message-Id: <1269252024-5271-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1269252024-5271-1-git-send-email-kwolf@redhat.com> References: <1269252024-5271-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/7] qemu-config: qemu_read_config_file() reads the normal config file List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com Introduce a new function qemu_read_config_file which reads the VM configuration from a config file. Unlike qemu_config_parse it doesn't take a open file but a filename and reduces code duplication as a side effect. Signed-off-by: Kevin Wolf --- qemu-config.c | 15 +++++++++++++++ qemu-config.h | 2 ++ vl.c | 38 +++++++++++++------------------------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 150157c..57dc9a5 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -489,3 +489,18 @@ out: loc_pop(&loc); return res; } + +int qemu_read_config_file(const char *filename) +{ + FILE *f = fopen(filename, "r"); + if (f == NULL) { + return -errno; + } + + if (qemu_config_parse(f, filename) != 0) { + return -EINVAL; + } + fclose(f); + + return 0; +} diff --git a/qemu-config.h b/qemu-config.h index f217c58..07a7a27 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -19,4 +19,6 @@ void qemu_add_globals(void); void qemu_config_write(FILE *fp); int qemu_config_parse(FILE *fp, const char *fname); +int qemu_read_config_file(const char *filename); + #endif /* QEMU_CONFIG_H */ diff --git a/vl.c b/vl.c index 6948157..08294ff 100644 --- a/vl.c +++ b/vl.c @@ -3828,25 +3828,17 @@ int main(int argc, char **argv, char **envp) } if (defconfig) { - const char *fname; - FILE *fp; + int ret; - fname = CONFIG_QEMU_CONFDIR "/qemu.conf"; - fp = fopen(fname, "r"); - if (fp) { - if (qemu_config_parse(fp, fname) != 0) { - exit(1); - } - fclose(fp); + ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf"); + if (ret == -EINVAL) { + exit(1); } - fname = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf"; - fp = fopen(fname, "r"); - if (fp) { - if (qemu_config_parse(fp, fname) != 0) { - exit(1); - } - fclose(fp); + ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR + "/target-" TARGET_ARCH ".conf"); + if (ret == -EINVAL) { + exit(1); } } #if defined(cpudef_setup) @@ -4522,16 +4514,12 @@ int main(int argc, char **argv, char **envp) #endif case QEMU_OPTION_readconfig: { - FILE *fp; - fp = fopen(optarg, "r"); - if (fp == NULL) { - fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); + int ret = qemu_read_config_file(optarg); + if (ret < 0) { + fprintf(stderr, "read config %s: %s\n", optarg, + strerror(-ret)); exit(1); } - if (qemu_config_parse(fp, optarg) != 0) { - exit(1); - } - fclose(fp); break; } case QEMU_OPTION_writeconfig: -- 1.6.6.1