From patchwork Thu Jul 12 13:40:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943053 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 41RHHh2YCwz9rxx for ; Thu, 12 Jul 2018 23:45:04 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4B714D3A; Thu, 12 Jul 2018 13:40:37 +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 B656CD3C for ; Thu, 12 Jul 2018 13:40:34 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 4765A4FA for ; Thu, 12 Jul 2018 13:40:34 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id v25-v6so5731739wmc.0 for ; Thu, 12 Jul 2018 06:40:34 -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=XSiLMlQSkrr13ba23H0kZgB8E0U67NehF3mkbPyZeo4=; b=V945eb5BhUgIKReiFUlnJz/cJfKJkIhZD9FEH+g9xXLS/uw2kHh/wde53bxhB8qR5/ QQcF2te3j7GIKVsNnzPHwBVWNft/y0TNEvccUYF9qC7/QXjW5gTeWHrgFqr67wd6jENm i0bWhCm4VQswocX9Z8gkAah5dNp4cRAxDg9N7N8Rcp8/Ki7qDtYgzCtH8GUBEorqS4Gz u0CnU/n9jxhi/mzPQtpOIMZcjh4i/ap5XLMx6IOT9Y6h2oLcMlcOfi6ZdQXJcAAYTm8d mAAvN4Ov3st0S/rUOvTwhM6tvE9PLUVbuLtwysySqgPHk+GOUJkw83wIsyVXTZzdTJ9+ cnlA== X-Gm-Message-State: AOUpUlGMIbILIZI+3ts3n0xXBmKh9xzCuz3x7GVRG8JEU7Icrj2Em8CR ljO8kUKBSxGk1EwS5PiX+5rAU2AotJA= X-Google-Smtp-Source: AAOMgpeVz9UZ8bidCzYwIaDEp6+2wGqMNNjYrqCKE14Zx1HOKsaRnpbsfyKDDFPnyizn4OEaNmb7bg== X-Received: by 2002:a1c:ed0d:: with SMTP id l13-v6mr1479431wmh.73.1531402832671; Thu, 12 Jul 2018 06:40:32 -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 s16-v6sm18201689wrq.20.2018.07.12.06.40.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Jul 2018 06:40:32 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Thu, 12 Jul 2018 15:40:10 +0200 Message-Id: <20180712134016.14336-10-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 09/15] ovn-nbctl: Propagate errors from prerequisites runner. 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 Instead of terminating the process, return the error to the caller. This will allow us to reuse the prerequisites runner in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 747aa63b6..154e7799a 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -82,8 +82,9 @@ static int leader_only = true; static void nbctl_cmd_init(void); OVS_NO_RETURN static void usage(void); static void parse_options(int argc, char *argv[], struct shash *local_options); -static void run_prerequisites(struct ctl_command[], size_t n_commands, - struct ovsdb_idl *); +static char * OVS_WARN_UNUSED_RESULT run_prerequisites(struct ctl_command[], + size_t n_commands, + struct ovsdb_idl *); static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args, struct ctl_command *, size_t n, struct ovsdb_idl *, bool *retry); @@ -101,6 +102,7 @@ main(int argc, char *argv[]) struct ctl_command *commands; struct shash local_options; size_t n_commands; + char *error; set_program_name(argv[0]); fatal_ignore_sigpipe(); @@ -125,9 +127,12 @@ main(int argc, char *argv[]) /* Initialize IDL. */ idl = the_idl = ovsdb_idl_create(db, &nbrec_idl_class, true, false); ovsdb_idl_set_leader_only(idl, leader_only); - run_prerequisites(commands, n_commands, idl); + error = run_prerequisites(commands, n_commands, idl); + if (error) { + ctl_fatal("%s", error); + } - char *error = main_loop(args, commands, n_commands, idl); + error = main_loop(args, commands, n_commands, idl); if (error) { ctl_fatal("%s", error); } @@ -4117,7 +4122,7 @@ static const struct ctl_table_class tables[NBREC_N_TABLES] = { [NBREC_TABLE_ACL].row_ids[0] = {&nbrec_acl_col_name, NULL, NULL}, }; -static void +static char * run_prerequisites(struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl) { @@ -4138,7 +4143,9 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, ctl_context_init(&ctx, c, idl, NULL, NULL, NULL); (c->syntax->prerequisites)(&ctx); if (ctx.error) { - ctl_fatal("%s", ctx.error); + char *error = xstrdup(ctx.error); + ctl_context_done(&ctx, c); + return error; } ctl_context_done(&ctx, c); @@ -4146,6 +4153,8 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, ovs_assert(!c->table); } } + + return NULL; } static char *