diff mbox series

[ovs-dev,v2,08/15] ovn-nbctl: Propagate errors from the main loop.

Message ID 20180712134016.14336-9-jkbs@redhat.com
State Superseded
Headers show
Series Daemon mode for ovn-nbctl | expand

Commit Message

Jakub Sitnicki July 12, 2018, 1:40 p.m. UTC
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@redhat.com>
---
 ovn/utilities/ovn-nbctl.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 6e136e1d0..747aa63b6 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[])
@@ -125,7 +127,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;
@@ -141,7 +146,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)
 {
@@ -169,10 +174,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;
             }
         }
 
@@ -181,6 +186,8 @@  main_loop(const char *args, struct ctl_command *commands, size_t n_commands,
             poll_block();
         }
     }
+
+    return NULL;
 }
 
 static void