]> git.proxmox.com Git - mirror_ovs.git/commitdiff
db-ctl-base: Don't die in create_symbol() on error.
authorJakub Sitnicki <jkbs@redhat.com>
Mon, 2 Jul 2018 10:50:02 +0000 (12:50 +0200)
committerBen Pfaff <blp@ovn.org>
Tue, 3 Jul 2018 20:19:02 +0000 (13:19 -0700)
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>
lib/db-ctl-base.c

index 92fe6065efbb5a864db0b8179e12385d1de3fb2f..61ca1d1b76fe6f29b9f30c45fa7fdb6ec50dba8a 100644 (file)
@@ -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