aboutsummaryrefslogtreecommitdiff
path: root/vl.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2010-03-05 17:25:55 +0100
committerKevin Wolf <kwolf@redhat.com>2010-04-23 16:08:45 +0200
commitdcfb0939bd7042c9d2622181263c01d78531f272 (patch)
tree3ab9d835fb9c0af3cb4a288fddee36dacdb6d2d7 /vl.c
parent6c557ab975fc8e5edb4167a241266c7c4657054a (diff)
qemu-config: qemu_read_config_file() reads the normal config file
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>
Diffstat (limited to 'vl.c')
-rw-r--r--vl.c35
1 files changed, 11 insertions, 24 deletions
diff --git a/vl.c b/vl.c
index e58441b8a1..fe2dd6fa91 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: