[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC][PATCH 1/7] qemu-config: qemu_read_config_file() reads
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [RFC][PATCH 1/7] qemu-config: qemu_read_config_file() reads the normal config file |
Date: |
Mon, 15 Mar 2010 18:08:29 +0100 |
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 <address@hidden>
---
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:
--
1.6.6.1
- [Qemu-devel] [RFC][PATCH 0/7] blkdebug, Kevin Wolf, 2010/03/15
- [Qemu-devel] [RFC][PATCH 2/7] qemu-config: Make qemu_config_parse more generic, Kevin Wolf, 2010/03/15
- [Qemu-devel] [RFC][PATCH 1/7] qemu-config: qemu_read_config_file() reads the normal config file,
Kevin Wolf <=
- [Qemu-devel] [RFC][PATCH 3/7] blkdebug: Basic request passthrough, Kevin Wolf, 2010/03/15
- [Qemu-devel] [RFC][PATCH 4/7] blkdebug: Inject errors, Kevin Wolf, 2010/03/15
- [Qemu-devel] [RFC][PATCH 5/7] Make qemu-config available for tools, Kevin Wolf, 2010/03/15
- [Qemu-devel] [RFC][PATCH 6/7] blkdebug: Add events and rules, Kevin Wolf, 2010/03/15