From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH v2 1/7] qemu-config: qemu_read_config_file() reads the normal config file
Date: Mon, 29 Mar 2010 16:52:42 +0200 [thread overview]
Message-ID: <1269874368-31011-2-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1269874368-31011-1-git-send-email-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 <kwolf@redhat.com>
---
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:
--
1.6.6.1
next prev parent reply other threads:[~2010-03-29 14:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-29 14:52 [Qemu-devel] [PATCH v2 0/7] blkdebug Kevin Wolf
2010-03-29 14:52 ` Kevin Wolf [this message]
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 2/7] qemu-config: Make qemu_config_parse more generic Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 3/7] blkdebug: Basic request passthrough Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 4/7] blkdebug: Inject errors Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 5/7] Make qemu-config available for tools Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 6/7] blkdebug: Add events and rules Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 7/7] qcow2: Trigger blkdebug events Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269874368-31011-2-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).