Browse Source

Fix error handling in qemu_read_config_file

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>
Kevin Wolf 15 years ago
parent
commit
019e78ba6e
2 changed files with 10 additions and 6 deletions
  1. 8 4
      qemu-config.c
  2. 2 2
      vl.c

+ 8 - 4
qemu-config.c

@@ -521,14 +521,18 @@ out:
 int qemu_read_config_file(const char *filename)
 int qemu_read_config_file(const char *filename)
 {
 {
     FILE *f = fopen(filename, "r");
     FILE *f = fopen(filename, "r");
+    int ret;
+
     if (f == NULL) {
     if (f == NULL) {
         return -errno;
         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);
     fclose(f);
 
 
-    return 0;
+    if (ret == 0) {
+        return 0;
+    } else {
+        return -EINVAL;
+    }
 }
 }

+ 2 - 2
vl.c

@@ -2662,12 +2662,12 @@ int main(int argc, char **argv, char **envp)
         int ret;
         int ret;
 
 
         ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
         ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
-        if (ret == -EINVAL) {
+        if (ret < 0 && ret != -ENOENT) {
             exit(1);
             exit(1);
         }
         }
 
 
         ret = qemu_read_config_file(arch_config_name);
         ret = qemu_read_config_file(arch_config_name);
-        if (ret == -EINVAL) {
+        if (ret < 0 && ret != -ENOENT) {
             exit(1);
             exit(1);
         }
         }
     }
     }