From patchwork Mon Mar 29 14:52:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 48865 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 DB152B7C98 for ; Tue, 30 Mar 2010 02:19:47 +1100 (EST) Received: from localhost ([127.0.0.1]:40446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwGgF-0003i0-90 for incoming@patchwork.ozlabs.org; Mon, 29 Mar 2010 11:15:07 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NwGNV-0005WO-AM for qemu-devel@nongnu.org; Mon, 29 Mar 2010 10:55:45 -0400 Received: from [140.186.70.92] (port=46645 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwGMF-0005PF-Sh for qemu-devel@nongnu.org; Mon, 29 Mar 2010 10:55:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NwGLG-0002ck-IS for qemu-devel@nongnu.org; Mon, 29 Mar 2010 10:53:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60039) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NwGLG-0002cf-B3 for qemu-devel@nongnu.org; Mon, 29 Mar 2010 10:53:26 -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 o2TErPr7010324 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 29 Mar 2010 10:53:25 -0400 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2TErLwB032108; Mon, 29 Mar 2010 10:53:23 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 29 Mar 2010 16:52:42 +0200 Message-Id: <1269874368-31011-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1269874368-31011-1-git-send-email-kwolf@redhat.com> References: <1269874368-31011-1-git-send-email-kwolf@redhat.com> 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: kwolf@redhat.com Subject: [Qemu-devel] [PATCH v2 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 --- 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 8a73235..6c022bf 100644 --- a/vl.c +++ b/vl.c @@ -3831,25 +3831,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) @@ -4525,16 +4517,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: