diff mbox series

[ovs-dev,v5,03/21] ovn-nbctl: Extract the main loop.

Message ID 20180719135126.19636-4-jkbs@redhat.com
State Accepted
Headers show
Series Daemon mode for ovn-nbctl | expand

Commit Message

Jakub Sitnicki July 19, 2018, 1:51 p.m. UTC
Split out a routine for the main ovn-nbctl loop.

Preparatory work for introducing daemon mode.

Signed-off-by: Jakub Sitnicki <jkbs@redhat.com>
---
 ovn/utilities/ovn-nbctl.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 47df19b23..a027553b7 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -88,6 +88,8 @@  static bool do_nbctl(const char *args, struct ctl_command *, size_t n,
                      struct ovsdb_idl *);
 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);
 
 int
 main(int argc, char *argv[])
@@ -95,7 +97,6 @@  main(int argc, char *argv[])
     struct ovsdb_idl *idl;
     struct ctl_command *commands;
     struct shash local_options;
-    unsigned int seqno;
     size_t n_commands;
 
     set_program_name(argv[0]);
@@ -123,6 +124,18 @@  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);
+
+    free(args);
+    exit(EXIT_SUCCESS);
+}
+
+static void
+main_loop(const char *args, struct ctl_command *commands, size_t n_commands,
+          struct ovsdb_idl *idl)
+{
+    unsigned int seqno;
+
     /* Execute the commands.
      *
      * 'seqno' is the database sequence number for which we last tried to
@@ -136,14 +149,13 @@  main(int argc, char *argv[])
         if (!ovsdb_idl_is_alive(idl)) {
             int retval = ovsdb_idl_get_last_error(idl);
             ctl_fatal("%s: database connection failed (%s)",
-                        db, ovs_retval_to_string(retval));
+                      db, ovs_retval_to_string(retval));
         }
 
         if (seqno != ovsdb_idl_get_seqno(idl)) {
             seqno = ovsdb_idl_get_seqno(idl);
             if (do_nbctl(args, commands, n_commands, idl)) {
-                free(args);
-                exit(EXIT_SUCCESS);
+                return;
             }
         }