[ovs-dev] [PATCH v4 12/21] ovn-nbctl: Propagate errors from prerequisites runner.

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


Instead of terminating the process, return the error to the caller.

This will allow us to reuse the prerequisites runner in daemon mode.

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

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index ee423577e..ecb351a80 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -82,8 +82,9 @@ static int leader_only = true;
 static void nbctl_cmd_init(void);
 OVS_NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[], struct shash *local_options);
-static void run_prerequisites(struct ctl_command[], size_t n_commands,
-                              struct ovsdb_idl *);
+static char * OVS_WARN_UNUSED_RESULT run_prerequisites(struct ctl_command[],
+                                                       size_t n_commands,
+                                                       struct ovsdb_idl *);
 static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args,
                                               struct ctl_command *, size_t n,
                                               struct ovsdb_idl *, bool *retry);
@@ -101,6 +102,7 @@ main(int argc, char *argv[])
     struct ctl_command *commands;
     struct shash local_options;
     size_t n_commands;
+    char *error;
 
     set_program_name(argv[0]);
     fatal_ignore_sigpipe();
@@ -113,8 +115,8 @@ main(int argc, char *argv[])
     char *args = process_escape_args(argv);
     shash_init(&local_options);
     parse_options(argc, argv, &local_options);
-    char *error = ctl_parse_commands(argc - optind, argv + optind,
-                                     &local_options, &commands, &n_commands);
+    error = ctl_parse_commands(argc - optind, argv + optind, &local_options,
+                               &commands, &n_commands);
     if (error) {
         ctl_fatal("%s", error);
     }
@@ -128,9 +130,12 @@ main(int argc, char *argv[])
     /* Initialize IDL. */
     idl = the_idl = ovsdb_idl_create(db, &nbrec_idl_class, true, false);
     ovsdb_idl_set_leader_only(idl, leader_only);
-    run_prerequisites(commands, n_commands, idl);
+    error = run_prerequisites(commands, n_commands, idl);
+    if (error) {
+        ctl_fatal("%s", error);
+    }
 
-    char *error = main_loop(args, commands, n_commands, idl);
+    error = main_loop(args, commands, n_commands, idl);
     if (error) {
         ctl_fatal("%s", error);
     }
@@ -4120,7 +4125,7 @@ static const struct ctl_table_class tables[NBREC_N_TABLES] = {
     [NBREC_TABLE_ACL].row_ids[0] = {&nbrec_acl_col_name, NULL, NULL},
 };
 
-static void
+static char *
 run_prerequisites(struct ctl_command *commands, size_t n_commands,
                   struct ovsdb_idl *idl)
 {
@@ -4141,7 +4146,9 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands,
             ctl_context_init(&ctx, c, idl, NULL, NULL, NULL);
             (c->syntax->prerequisites)(&ctx);
             if (ctx.error) {
-                ctl_fatal("%s", ctx.error);
+                char *error = xstrdup(ctx.error);
+                ctl_context_done(&ctx, c);
+                return error;
             }
             ctl_context_done(&ctx, c);
 
@@ -4149,6 +4156,8 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands,
             ovs_assert(!c->table);
         }
     }
+
+    return NULL;
 }
 
 static char *
-- 
2.14.4



More information about the dev mailing list