[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/26] qemu-config: qemu_read_config_file() reads th
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 01/26] qemu-config: qemu_read_config_file() reads the normal config file |
Date: |
Fri, 23 Apr 2010 17:30:33 +0200 |
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 | 35 +++++++++++------------------------
3 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/qemu-config.c b/qemu-config.c
index d4a2f43..8254b35 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -488,3 +488,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 e58441b..fe2dd6f 100644
--- a/vl.c
+++ b/vl.c
@@ -2653,25 +2653,16 @@ 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 = arch_config_name;
- fp = fopen(fname, "r");
- if (fp) {
- if (qemu_config_parse(fp, fname) != 0) {
- exit(1);
- }
- fclose(fp);
+ ret = qemu_read_config_file(arch_config_name);
+ if (ret == -EINVAL) {
+ exit(1);
}
}
cpudef_init();
@@ -3327,16 +3318,12 @@ int main(int argc, char **argv, char **envp)
break;
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
- [Qemu-devel] [PULL 00/26] Block patches, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 01/26] qemu-config: qemu_read_config_file() reads the normal config file,
Kevin Wolf <=
- [Qemu-devel] [PATCH 02/26] qemu-config: Make qemu_config_parse more generic, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 04/26] blkdebug: Inject errors, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 03/26] blkdebug: Basic request passthrough, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 05/26] Make qemu-config available for tools, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 06/26] blkdebug: Add events and rules, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 08/26] qcow2: Fix creation of large images, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 09/26] Replace calls of old bdrv_open, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 13/26] qcow2: Fix error return code in qcow2_alloc_cluster_link_l2, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 10/26] block: get rid of the BDRV_O_FILE flag, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 12/26] qcow2: Return 0/-errno in write_l2_entries, Kevin Wolf, 2010/04/23