From patchwork Mon Mar 15 17:08:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 47767 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 DF867B7D6E for ; Tue, 16 Mar 2010 04:13:22 +1100 (EST) Received: from localhost ([127.0.0.1]:39350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrDqx-0005Na-OH for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2010 13:13:19 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrDn7-0004Ll-ND for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:21 -0400 Received: from [199.232.76.173] (port=60309 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrDn6-0004Lb-A4 for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:20 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NrDn4-0005qZ-R8 for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33736) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NrDn4-0005qM-1o for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:18 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2FH9GeH004984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 15 Mar 2010 13:09:17 -0400 Received: from localhost.localdomain (vpn1-6-64.ams2.redhat.com [10.36.6.64]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2FH9CWf018739; Mon, 15 Mar 2010 13:09:15 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 15 Mar 2010 18:08:29 +0100 Message-Id: <1268672915-12233-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1268672915-12233-1-git-send-email-kwolf@redhat.com> References: <1268672915-12233-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com Subject: [Qemu-devel] [RFC][PATCH 1/7] qemu-config: qemu_read_config_file() reads the normal config file 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 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 Reviewed-by: Christoph Hellwig --- qemu-config.c | 15 +++++++++++++++ qemu-config.h | 2 ++ vl.c | 34 +++++++++++++--------------------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 246fae6..8166b5e 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -473,3 +473,18 @@ int qemu_config_parse(FILE *fp) } return 0; } + +int qemu_read_config_file(const char *filename) +{ + FILE *f = fopen(filename, "r"); + if (f == NULL) { + return -errno; + } + + if (qemu_config_parse(f) != 0) { + return -EINVAL; + } + fclose(f); + + return 0; +} diff --git a/qemu-config.h b/qemu-config.h index b335c42..bbe9d41 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -18,4 +18,6 @@ void qemu_add_globals(void); void qemu_config_write(FILE *fp); int qemu_config_parse(FILE *fp); +int qemu_read_config_file(const char *filename); + #endif /* QEMU_CONFIG_H */ diff --git a/vl.c b/vl.c index a3e43ad..078e3f9 100644 --- a/vl.c +++ b/vl.c @@ -4940,21 +4940,17 @@ int main(int argc, char **argv, char **envp) } if (defconfig) { - FILE *fp; - fp = fopen(CONFIG_QEMU_CONFDIR "/qemu.conf", "r"); - if (fp) { - if (qemu_config_parse(fp) != 0) { - exit(1); - } - fclose(fp); + int ret; + + ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf"); + if (ret == -EINVAL) { + exit(1); } - fp = fopen(CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", "r"); - if (fp) { - if (qemu_config_parse(fp) != 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) @@ -5635,16 +5631,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) != 0) { - exit(1); - } - fclose(fp); break; } case QEMU_OPTION_writeconfig: