[ovs-dev] [PATCH v4 11/21] ovn-nbctl: Propagate errors from the main loop.

Jakub Sitnicki jkbs at redhat.com
Thu Jul 19 12:36:22 UTC 2018


Let the caller handle the errors instead of reporting it and
terminating. Prepare for reusing the main loop in daemon mode.

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

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index e660b2cdf..ee423577e 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -89,8 +89,10 @@ static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args,
                                               struct ovsdb_idl *, bool *retry);
 static const struct nbrec_dhcp_options *dhcp_options_get(
     struct ctl_context *ctx, const char *id, bool must_exist);
-static void main_loop(const char *args, struct ctl_command *commands,
-                      size_t n_commands, struct ovsdb_idl *idl);
+static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args,
+                                               struct ctl_command *commands,
+                                               size_t n_commands,
+                                               struct ovsdb_idl *idl);
 
 int
 main(int argc, char *argv[])
@@ -128,7 +130,10 @@ main(int argc, char *argv[])
     ovsdb_idl_set_leader_only(idl, leader_only);
     run_prerequisites(commands, n_commands, idl);
 
-    main_loop(args, commands, n_commands, idl);
+    char *error = main_loop(args, commands, n_commands, idl);
+    if (error) {
+        ctl_fatal("%s", error);
+    }
 
     ovsdb_idl_destroy(idl);
     idl = the_idl = NULL;
@@ -144,7 +149,7 @@ main(int argc, char *argv[])
     exit(EXIT_SUCCESS);
 }
 
-static void
+static char *
 main_loop(const char *args, struct ctl_command *commands, size_t n_commands,
           struct ovsdb_idl *idl)
 {
@@ -172,10 +177,10 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands,
             bool retry;
             char *error = do_nbctl(args, commands, n_commands, idl, &retry);
             if (error) {
-                ctl_fatal("%s", error);
+                return error;
             }
             if (!retry) {
-                return;
+                return NULL;
             }
         }
 
@@ -184,6 +189,8 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands,
             poll_block();
         }
     }
+
+    return NULL;
 }
 
 static void
-- 
2.14.4



More information about the dev mailing list