[ovs-dev] [PATCH v2 03/15] ovn-nbctl: Extract the main loop.

Jakub Sitnicki jkbs at redhat.com
Thu Jul 12 13:40:04 UTC 2018


Split out a routine for the main ovn-nbctl loop.

Preparatory work for introducing daemon mode.

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

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;
             }
         }
 
-- 
2.14.4



More information about the dev mailing list