From patchwork Mon May 17 08:36:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 52765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2F940B7DB2 for ; Mon, 17 May 2010 18:39:47 +1000 (EST) Received: from localhost ([127.0.0.1]:45463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ODvrU-0006CW-AQ for incoming@patchwork.ozlabs.org; Mon, 17 May 2010 04:39:44 -0400 Received: from [140.186.70.92] (port=57554 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ODvp0-0005Sh-KQ for qemu-devel@nongnu.org; Mon, 17 May 2010 04:37:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ODvoz-0000FQ-4s for qemu-devel@nongnu.org; Mon, 17 May 2010 04:37:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48070) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1ODvoy-0000FE-Ti for qemu-devel@nongnu.org; Mon, 17 May 2010 04:37:09 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4H8b7Um025149 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 17 May 2010 04:37:07 -0400 Received: from localhost.localdomain (dhcp-5-217.str.redhat.com [10.32.5.217]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4H8b6wO025051; Mon, 17 May 2010 04:37:06 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 17 May 2010 10:36:47 +0200 Message-Id: <1274085407-8106-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH] Fix error handling in qemu_read_config_file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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); } }