diff mbox series

[ovs-dev,04/23] db-ctl-base: Don't die in check_mutable() on error.

Message ID 20180702105019.10345-5-jkbs@redhat.com
State Accepted
Headers show
Series Don't use ctl_fatal() in command handlers from db-ctl-base | expand

Commit Message

Jakub Sitnicki July 2, 2018, 10:50 a.m. UTC
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>
---
 lib/db-ctl-base.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index a826dfb94..7bcc08fe3 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -634,14 +634,17 @@  pre_parse_column_key_value(struct ctl_context *ctx,
     return column;
 }
 
-static void
+/* Checks if the 'column' is mutable. Returns NULL if it is mutable, or a
+ * malloc()'ed error message otherwise. */
+static char * OVS_WARN_UNUSED_RESULT
 check_mutable(const struct ovsdb_idl_row *row,
               const struct ovsdb_idl_column *column)
 {
     if (!ovsdb_idl_is_mutable(row, column)) {
-        ctl_fatal("cannot modify read-only column %s in table %s",
-                  column->name, row->table->class_->name);
+        return xasprintf("cannot modify read-only column %s in table %s",
+                         column->name, row->table->class_->name);
     }
+    return NULL;
 }
 
 #define RELOPS                                  \
@@ -1210,7 +1213,7 @@  set_column(const struct ovsdb_idl_table_class *table,
     if (!value_string) {
         ctl_fatal("%s: missing value", arg);
     }
-    check_mutable(row, column);
+    die_if_error(check_mutable(row, column));
 
     if (key_string) {
         union ovsdb_atom key, value;
@@ -1316,7 +1319,7 @@  cmd_add(struct ctl_context *ctx)
     if (!row) {
         return;
     }
-    check_mutable(row, column);
+    die_if_error(check_mutable(row, column));
 
     type = &column->type;
     ovsdb_datum_clone(&old, ovsdb_idl_read(row, column), &column->type);
@@ -1377,7 +1380,7 @@  cmd_remove(struct ctl_context *ctx)
     if (!row) {
         return;
     }
-    check_mutable(row, column);
+    die_if_error(check_mutable(row, column));
 
     type = &column->type;
     ovsdb_datum_clone(&old, ovsdb_idl_read(row, column), &column->type);
@@ -1455,7 +1458,7 @@  cmd_clear(struct ctl_context *ctx)
         struct ovsdb_datum datum;
 
         die_if_error(get_column(table, ctx->argv[i], &column));
-        check_mutable(row, column);
+        die_if_error(check_mutable(row, column));
 
         type = &column->type;
         if (type->n_min > 0) {