From patchwork Sat Mar 2 06:58:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Goldstein X-Patchwork-Id: 224467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 550332C02EE for ; Sat, 2 Mar 2013 18:00:20 +1100 (EST) Received: from localhost ([::1]:60238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBgQc-0004kH-Ju for incoming@patchwork.ozlabs.org; Sat, 02 Mar 2013 02:00:18 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBgPN-0003Ig-3v for qemu-devel@nongnu.org; Sat, 02 Mar 2013 01:59:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBgPK-0003MR-88 for qemu-devel@nongnu.org; Sat, 02 Mar 2013 01:59:00 -0500 Received: from mail-gh0-f182.google.com ([209.85.160.182]:56743) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBgPK-0003MN-0U for qemu-devel@nongnu.org; Sat, 02 Mar 2013 01:58:58 -0500 Received: by mail-gh0-f182.google.com with SMTP id z15so602439ghb.27 for ; Fri, 01 Mar 2013 22:58:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=q/CiE6oC6qB/6LMuMC5b6q+BqiodSUKZFm3C+wycodk=; b=GpaA1tChXwveRBjxjRP1bp+VIrsRJUupNCyOMsQzN7E/cf92ydgY+Y5n/g9Eg59hBt c+47kDLheP59imJ0WBMA5iiXs37P6o/OXTCpGxxuGC7yS2YKPUIDAyU1w9LjU3FU6fr/ 18osxttGt54OvTZ+jNbLtIgQjlSulp/LEIXnUthsCDs3yXA/dipPMHR2KdvFEH9WcIrN YrF+FbKv0RG+HUl5jQ7XvPXWfeF2Vw21w3wB/HVUyo63Js6mjnVNt+Qx+xeS8/pJ63Yj abpKLvGobzpGmPQ9xJiUCpID+4GhxdXUTJarW3Z1YSmkdjpbDvVtslBG/8mj9pY50PPC 5FsQ== X-Received: by 10.236.139.230 with SMTP id c66mr9198704yhj.168.1362207537498; Fri, 01 Mar 2013 22:58:57 -0800 (PST) Received: from localhost.localdomain (c-68-62-173-137.hsd1.al.comcast.net. [68.62.173.137]) by mx.google.com with ESMTPS id s34sm23304914yhe.9.2013.03.01.22.58.56 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Mar 2013 22:58:57 -0800 (PST) From: Doug Goldstein To: qemu-devel@nongnu.org Date: Sat, 2 Mar 2013 00:58:47 -0600 Message-Id: <1362207528-27804-2-git-send-email-cardoe@cardoe.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1362207528-27804-1-git-send-email-cardoe@cardoe.com> References: <1361757620-23318-1-git-send-email-cardoe@cardoe.com> <1362207528-27804-1-git-send-email-cardoe@cardoe.com> X-Gm-Message-State: ALoCoQmANAJXhCjEEBgBB9UaaKkRbjSyfV9nfCbKIVKCo9tWrUUfbIM85MSnq3eA/GhsGjgdT8sO X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.182 Cc: Anthony Liguori , Corey Bryant , Doug Goldstein , Richa Marwaha Subject: [Qemu-devel] [PATCHv2 1/2] bridge helper: unified error cleanup for parse_acl_file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Handle errors and cleanup from the error in a unified place for parse_acl_file(). Signed-off-by: Doug Goldstein CC: Anthony Liguori CC: Richa Marwaha CC: Corey Bryant TO: qemu-devel@nongnu.org --- qemu-bridge-helper.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 287bfd5..ee67740 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -74,11 +74,12 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) { FILE *f; char line[4096]; + int ret = -EINVAL; ACLRule *acl_rule; f = fopen(filename, "r"); if (f == NULL) { - return -1; + return -errno; } while (fgets(line, sizeof(line), f) != NULL) { @@ -102,9 +103,8 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) if (arg == NULL) { fprintf(stderr, "Invalid config line:\n %s\n", line); - fclose(f); - errno = EINVAL; - return -1; + ret = -EINVAL; + goto failure; } *arg = 0; @@ -142,15 +142,17 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) parse_acl_file(arg, acl_list); } else { fprintf(stderr, "Unknown command `%s'\n", cmd); - fclose(f); - errno = EINVAL; - return -1; + ret = -EINVAL; + goto failure; } } + ret = 0; + +failure: fclose(f); - return 0; + return ret; } static bool has_vnet_hdr(int fd) @@ -272,7 +274,7 @@ int main(int argc, char **argv) /* parse default acl file */ QSIMPLEQ_INIT(&acl_list); - if (parse_acl_file(DEFAULT_ACL_FILE, &acl_list) == -1) { + if (parse_acl_file(DEFAULT_ACL_FILE, &acl_list) < 0) { fprintf(stderr, "failed to parse default acl file `%s'\n", DEFAULT_ACL_FILE); ret = EXIT_FAILURE;