]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
Fix error handling in qemu_read_config_file
authorKevin Wolf <kwolf@redhat.com>
Mon, 17 May 2010 08:36:47 +0000 (10:36 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Mon, 24 May 2010 20:18:23 +0000 (15:18 -0500)
We need to close the file even in error case. While at it, make the callers
catch all kind of errors. ENOENT is allowed for default config files, they
are optional.

Reported-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qemu-config.c
vl.c

index d5008851cb26c11d7ccd0fff86c88f01a2b6d97f..aa376d450adfa21cafac6a8d472685ed03130225 100644 (file)
@@ -521,14 +521,18 @@ out:
 int qemu_read_config_file(const char *filename)
 {
     FILE *f = fopen(filename, "r");
+    int ret;
+
     if (f == NULL) {
         return -errno;
     }
 
-    if (qemu_config_parse(f, vm_config_groups, filename) != 0) {
-        return -EINVAL;
-    }
+    ret = qemu_config_parse(f, vm_config_groups, filename);
     fclose(f);
 
-    return 0;
+    if (ret == 0) {
+        return 0;
+    } else {
+        return -EINVAL;
+    }
 }
diff --git a/vl.c b/vl.c
index 8c818f0d24d43b75a0b047bc0692d4ed4e50dc59..328395e3dda7e657a4c9306322a9aaab263c53ad 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -2662,12 +2662,12 @@ int main(int argc, char **argv, char **envp)
         int ret;
 
         ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
-        if (ret == -EINVAL) {
+        if (ret < 0 && ret != -ENOENT) {
             exit(1);
         }
 
         ret = qemu_read_config_file(arch_config_name);
-        if (ret == -EINVAL) {
+        if (ret < 0 && ret != -ENOENT) {
             exit(1);
         }
     }