qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH] Fix error handling in qemu_read_config_file
Date: Mon, 17 May 2010 10:36:47 +0200	[thread overview]
Message-ID: <1274085407-8106-1-git-send-email-kwolf@redhat.com> (raw)

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>
---
 qemu-config.c |   12 ++++++++----
 vl.c          |    4 ++--
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/qemu-config.c b/qemu-config.c
index bf3d493..b2a4128 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -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 c8abce6..4ca1bee 100644
--- a/vl.c
+++ b/vl.c
@@ -2683,12 +2683,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);
         }
     }
-- 
1.6.6.1

             reply	other threads:[~2010-05-17  8:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-17  8:36 Kevin Wolf [this message]
2010-05-24 20:30 ` [Qemu-devel] [PATCH] Fix error handling in qemu_read_config_file Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1274085407-8106-1-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).