summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJakub Sitnicki <jkbs@redhat.com>2018-07-02 12:50:02 +0200
committerBen Pfaff <blp@ovn.org>2018-07-03 13:19:02 -0700
commit9065ca453aa33f9271aeba39cfcafa63ff7ae607 (patch)
tree886646b99581b28f4733ce3bfa88eeeb3352c696 /lib
parent79c1a00fb5a5ff93658e0f0b910d45fc2354d6af (diff)
downloadopenvswitch-9065ca453aa33f9271aeba39cfcafa63ff7ae607.tar.gz
db-ctl-base: Don't die in create_symbol() on error.
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 <jkbs@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/db-ctl-base.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index 92fe6065e..61ca1d1b7 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