From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=51081 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGeIM-0003k8-6m for qemu-devel@nongnu.org; Mon, 24 May 2010 16:30:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGeIG-0002Rn-9c for qemu-devel@nongnu.org; Mon, 24 May 2010 16:30:41 -0400 Received: from mail-px0-f173.google.com ([209.85.212.173]:40304) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGeIF-0002Rg-UN for qemu-devel@nongnu.org; Mon, 24 May 2010 16:30:36 -0400 Received: by pxi19 with SMTP id 19so1700702pxi.4 for ; Mon, 24 May 2010 13:30:34 -0700 (PDT) Message-ID: <4BFAE1E6.5010005@codemonkey.ws> Date: Mon, 24 May 2010 15:30:30 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] Fix error handling in qemu_read_config_file References: <1274085407-8106-1-git-send-email-kwolf@redhat.com> In-Reply-To: <1274085407-8106-1-git-send-email-kwolf@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org, lcapitulino@redhat.com On 05/17/2010 03:36 AM, Kevin Wolf wrote: > 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 > Signed-off-by: Kevin Wolf > Applied. Thanks. Regards, Anthony Liguori > --- > 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); > } > } >