From patchwork Thu Jul 12 13:40:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943052 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41RHH51wlDz9rxx for ; Thu, 12 Jul 2018 23:44:33 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 79DEFD3D; Thu, 12 Jul 2018 13:40:35 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id EFE91D32 for ; Thu, 12 Jul 2018 13:40:32 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 733FF76A for ; Thu, 12 Jul 2018 13:40:32 +0000 (UTC) Received: by mail-wm0-f42.google.com with SMTP id w16-v6so5676237wmc.2 for ; Thu, 12 Jul 2018 06:40:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DS+vRToPFcrL1cxulJGQ0TJDm8UfBsmxjUVDtkhi6MM=; b=d5WgKpI2ZXT5TZ/cxBZEGcZQPIKynUWAPzllWW35X/lGKrY4wgBq5rc+/Ttms09+id jFNYOAq/HPVIjiMaoJ/n6aW2umg3RC70noew01iEjrVrYhSW6h4OiCqov5jEiXxEQ7GQ MQVslJuu8SMYgkL3eLNQ6DuHCXPsY1fpP5pXzEbl5mIi7qk1wBbQWMozDm9gV0YLGR7i GzFi9X8ZEq/Gg/iAdfw4j7sUfUWvcsA7NPYI6MtsmqoX3Lt/cDAGwr+nBTEX1GfJXCHd hV4VwQbkyW09TRT2+B/AQgxGE+cWUZEZXCYn9r3wcj02UWog0LiDezajZPOILevIoItH 1APA== X-Gm-Message-State: AOUpUlHwK8aZ+cbAxjjY2g0fdIj9CqREDviIpAdXbWMpJJoTDNEfVjcV +AXzhZ4xNaG/wsbQBchz1co8YHrDm4k= X-Google-Smtp-Source: AAOMgpcB7sA+aGGSUXog+v8pFdhcgGhnhZram98LiX/EK005NWfrLb9IMi9PjyMvdV6rVy6J71mx4A== X-Received: by 2002:a1c:864c:: with SMTP id i73-v6mr1514185wmd.40.1531402830977; Thu, 12 Jul 2018 06:40:30 -0700 (PDT) Received: from redhat.com (red-hat-inc.vlan404.asr1.mad1.gblx.net. [64.215.113.190]) by smtp.gmail.com with ESMTPSA id w4-v6sm6083927wrt.40.2018.07.12.06.40.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Jul 2018 06:40:30 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Thu, 12 Jul 2018 15:40:09 +0200 Message-Id: <20180712134016.14336-9-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180712134016.14336-1-jkbs@redhat.com> References: <20180712134016.14336-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 08/15] ovn-nbctl: Propagate errors from the main loop. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Let the caller handle the errors instead of reporting it and terminating. Prepare for reusing the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 6e136e1d0..747aa63b6 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -89,8 +89,10 @@ static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args, struct ovsdb_idl *, bool *retry); static const struct nbrec_dhcp_options *dhcp_options_get( struct ctl_context *ctx, const char *id, bool must_exist); -static void main_loop(const char *args, struct ctl_command *commands, - size_t n_commands, struct ovsdb_idl *idl); +static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args, + struct ctl_command *commands, + size_t n_commands, + struct ovsdb_idl *idl); int main(int argc, char *argv[]) @@ -125,7 +127,10 @@ main(int argc, char *argv[]) ovsdb_idl_set_leader_only(idl, leader_only); run_prerequisites(commands, n_commands, idl); - main_loop(args, commands, n_commands, idl); + char *error = main_loop(args, commands, n_commands, idl); + if (error) { + ctl_fatal("%s", error); + } ovsdb_idl_destroy(idl); idl = the_idl = NULL; @@ -141,7 +146,7 @@ main(int argc, char *argv[]) exit(EXIT_SUCCESS); } -static void +static char * main_loop(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl) { @@ -169,10 +174,10 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, bool retry; char *error = do_nbctl(args, commands, n_commands, idl, &retry); if (error) { - ctl_fatal("%s", error); + return error; } if (!retry) { - return; + return NULL; } } @@ -181,6 +186,8 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, poll_block(); } } + + return NULL; } static void