[ovs-dev] [PATCH 09/30] ovn-nbctl: Don't die in parse_enabled().

Jakub Sitnicki jkbs at redhat.com
Sat Jul 7 11:09:43 UTC 2018


Let the caller handle the error.

Signed-off-by: Jakub Sitnicki <jkbs at redhat.com>
---
 ovn/utilities/ovn-nbctl.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 56558ddd0..f519c6c92 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -1285,16 +1285,20 @@ nbctl_lsp_get_up(struct ctl_context *ctx)
                   "%s\n", (lsp->up && *lsp->up) ? "up" : "down");
 }
 
-static bool
-parse_enabled(const char *state)
+static char * OVS_WARN_UNUSED_RESULT
+parse_enabled(const char *state, bool *enabled_p)
 {
+    ovs_assert(enabled_p);
+
     if (!strcasecmp(state, "enabled")) {
-        return true;
+        *enabled_p = true;
     } else if (!strcasecmp(state, "disabled")) {
-        return false;
+        *enabled_p = false;
     } else {
-        ctl_fatal("%s: state must be \"enabled\" or \"disabled\"", state);
+        return xasprintf("%s: state must be \"enabled\" or \"disabled\"",
+                         state);
     }
+    return NULL;
 }
 
 static void
@@ -1308,7 +1312,11 @@ nbctl_lsp_set_enabled(struct ctl_context *ctx)
     if (error) {
         ctl_fatal("%s", error);
     }
-    bool enabled = parse_enabled(state);
+    bool enabled;
+    error = parse_enabled(state, &enabled);
+    if (error) {
+        ctl_fatal("%s", error);
+    }
     nbrec_logical_switch_port_set_enabled(lsp, &enabled, 1);
 }
 
@@ -3592,7 +3600,11 @@ nbctl_lrp_set_enabled(struct ctl_context *ctx)
         return;
     }
 
-    bool enabled = parse_enabled(state);
+    bool enabled;
+    error = parse_enabled(state, &enabled);
+    if (error) {
+        ctl_fatal("%s", error);
+    }
     nbrec_logical_router_port_set_enabled(lrp, &enabled, 1);
 }
 
-- 
2.14.4



More information about the dev mailing list