From patchwork Mon Jul 2 10:50:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 937793 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 41K3xw0vXnz9s3q for ; Mon, 2 Jul 2018 20:53:08 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AFC17CBF; Mon, 2 Jul 2018 10:50:40 +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 038C7CC7 for ; Mon, 2 Jul 2018 10:50:39 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr0-f179.google.com (mail-wr0-f179.google.com [209.85.128.179]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 75AC7689 for ; Mon, 2 Jul 2018 10:50:38 +0000 (UTC) Received: by mail-wr0-f179.google.com with SMTP id s11-v6so5806684wra.13 for ; Mon, 02 Jul 2018 03:50:38 -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:subject:date:message-id:in-reply-to :references; bh=wqpotnmXwBZg3NvxIppySHS70ioymu6A00uDR08djzc=; b=TG5sxNWhgbY4zdFVxHC/crolnXUoAM6KhUW50Evm2ecx8lWsku9YIV0DERcETmlatX KwAoWW7l4IHp4K5w99ZuQN/B50gIrUt1y9ryHSwgK6fbJGEjNw9air+XK4AdcVh+BJY8 SlXeAgHRxLvCctLmXDOHOpNOB0ONyJk61cLbiLdW6nD2BTdtBizZZJvBJsPhmphZzVZR dkLMe/sEsPbr1YhXwMllt1GPGY1dvOD7YPAZg1euB5W25HOCQjdtr7OQboZhRUJG44Qx B/puaLsNp1K0tofA7hflg1UwyH74MWQ9RzjUOsmXy0XKruFgyyZkcH1tHfpgwAd//4Hh VQ+A== X-Gm-Message-State: APt69E2XnKqNuspCs33+6ddPi+y/V9JenS5a24i01oCWgqoKq9vPjLm6 hLiTdIp+y8T8hHvIHvqhTes0YhW/LGQ= X-Google-Smtp-Source: AAOMgpcS07wQ+IQ8Wpeb07ovVJhZBP+CHbhdlJEPgqZ8hRmgRpxJK/jSR7XvAahvNDtTdsAc2TOTnA== X-Received: by 2002:adf:ce04:: with SMTP id p4-v6mr114313wrn.275.1530528636901; Mon, 02 Jul 2018 03:50:36 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id g75-v6sm9041025wmd.38.2018.07.02.03.50.35 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Jul 2018 03:50:36 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 2 Jul 2018 12:50:02 +0200 Message-Id: <20180702105019.10345-7-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180702105019.10345-1-jkbs@redhat.com> References: <20180702105019.10345-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 06/23] db-ctl-base: Don't die in create_symbol() on error. 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 Return the error message to the caller instead of reporting it and dying so that the caller can handle the error without terminating the process if needed. Signed-off-by: Jakub Sitnicki --- lib/db-ctl-base.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index 429612c2c..e8f66811a 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -222,13 +222,18 @@ score_partial_match(const char *name, const char *s) return *s == '\0' ? score : 0; } -static struct ovsdb_symbol * -create_symbol(struct ovsdb_symbol_table *symtab, const char *id, bool *newp) +/* Returns NULL and sets 'symbolp' and 'newp' if symbol was created + * successfully. Otherwise returns a malloc()'ed error message on failure. */ +static char * OVS_WARN_UNUSED_RESULT +create_symbol(struct ovsdb_symbol_table *symtab, const char *id, + struct ovsdb_symbol **symbolp, bool *newp) { struct ovsdb_symbol *symbol; + ovs_assert(symbolp); + if (id[0] != '@') { - ctl_fatal("row id \"%s\" does not begin with \"@\"", id); + return xasprintf("row id \"%s\" does not begin with \"@\"", id); } if (newp) { @@ -237,11 +242,12 @@ create_symbol(struct ovsdb_symbol_table *symtab, const char *id, bool *newp) symbol = ovsdb_symbol_table_insert(symtab, id); if (symbol->created) { - ctl_fatal("row id \"%s\" may only be specified on one --id option", - id); + return xasprintf("row id \"%s\" may only be specified on one --id " + "option", id); } symbol->created = true; - return symbol; + *symbolp = symbol; + return NULL; } static bool @@ -878,7 +884,7 @@ cmd_get(struct ctl_context *ctx) struct ovsdb_symbol *symbol; bool new; - symbol = create_symbol(ctx->symtab, id, &new); + die_if_error(create_symbol(ctx->symtab, id, &symbol, &new)); if (!new) { ctl_fatal("row id \"%s\" specified on \"get\" command was used " "before it was defined", id); @@ -1521,7 +1527,9 @@ cmd_create(struct ctl_context *ctx) die_if_error(get_table(table_name, &table)); if (id) { - struct ovsdb_symbol *symbol = create_symbol(ctx->symtab, id, NULL); + struct ovsdb_symbol *symbol; + + die_if_error(create_symbol(ctx->symtab, id, &symbol, NULL)); if (table->is_root) { /* This table is in the root set, meaning that rows created in it * won't disappear even if they are unreferenced, so disable