summaryrefslogtreecommitdiff
path: root/ovn/utilities/ovn-nbctl.c
diff options
context:
space:
mode:
authorJakub Sitnicki <jkbs@redhat.com>2018-07-17 15:34:11 +0200
committerBen Pfaff <blp@ovn.org>2018-07-23 15:33:18 -0700
commit3844c85de979febe69c77766ae0baaf1d2b407e9 (patch)
tree38087fbb9e6e91294d6c00bee1bd78e67b35d347 /ovn/utilities/ovn-nbctl.c
parenta139410789e7aafc74631ed4c0e7103312bb2a52 (diff)
downloadopenvswitch-3844c85de979febe69c77766ae0baaf1d2b407e9.tar.gz
ovn-nbctl: Don't die in dhcp_options_get().
Let the caller handle the error. This prepares us for reporting errors in daemon mode. Signed-off-by: Jakub Sitnicki <jkbs@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'ovn/utilities/ovn-nbctl.c')
-rw-r--r--ovn/utilities/ovn-nbctl.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index a4a533740..69ccc3902 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -86,8 +86,9 @@ static void run_prerequisites(struct ctl_command[], size_t n_commands,
struct ovsdb_idl *);
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 char * OVS_WARN_UNUSED_RESULT dhcp_options_get(
+ struct ctl_context *ctx, const char *id, bool must_exist,
+ const struct nbrec_dhcp_options **);
int
main(int argc, char *argv[])
@@ -1448,7 +1449,10 @@ nbctl_lsp_set_dhcpv4_options(struct ctl_context *ctx)
}
const struct nbrec_dhcp_options *dhcp_opt = NULL;
if (ctx->argc == 3 ) {
- dhcp_opt = dhcp_options_get(ctx, ctx->argv[2], true);
+ error = dhcp_options_get(ctx, ctx->argv[2], true, &dhcp_opt);
+ if (error) {
+ ctl_fatal("%s", error);
+ }
}
if (dhcp_opt) {
@@ -1475,7 +1479,10 @@ nbctl_lsp_set_dhcpv6_options(struct ctl_context *ctx)
}
const struct nbrec_dhcp_options *dhcp_opt = NULL;
if (ctx->argc == 3) {
- dhcp_opt = dhcp_options_get(ctx, ctx->argv[2], true);
+ error = dhcp_options_get(ctx, ctx->argv[2], true, &dhcp_opt);
+ if (error) {
+ ctl_fatal("%s", error);
+ }
}
if (dhcp_opt) {
@@ -2697,8 +2704,9 @@ nbctl_lr_list(struct ctl_context *ctx)
free(nodes);
}
-static const struct nbrec_dhcp_options *
-dhcp_options_get(struct ctl_context *ctx, const char *id, bool must_exist)
+static char *
+dhcp_options_get(struct ctl_context *ctx, const char *id, bool must_exist,
+ const struct nbrec_dhcp_options **dhcp_opts_p)
{
struct uuid dhcp_opts_uuid;
const struct nbrec_dhcp_options *dhcp_opts = NULL;
@@ -2707,9 +2715,10 @@ dhcp_options_get(struct ctl_context *ctx, const char *id, bool must_exist)
}
if (!dhcp_opts && must_exist) {
- ctl_fatal("%s: dhcp options UUID not found", id);
+ return xasprintf("%s: dhcp options UUID not found", id);
}
- return dhcp_opts;
+ *dhcp_opts_p = dhcp_opts;
+ return NULL;
}
static void
@@ -2751,8 +2760,11 @@ nbctl_dhcp_options_create(struct ctl_context *ctx)
static void
nbctl_dhcp_options_set_options(struct ctl_context *ctx)
{
- const struct nbrec_dhcp_options *dhcp_opts = dhcp_options_get(
- ctx, ctx->argv[1], true);
+ const struct nbrec_dhcp_options *dhcp_opts;
+ char *error = dhcp_options_get(ctx, ctx->argv[1], true, &dhcp_opts);
+ if (error) {
+ ctl_fatal("%s", error);
+ }
struct smap dhcp_options = SMAP_INITIALIZER(&dhcp_options);
for (size_t i = 2; i < ctx->argc; i++) {
@@ -2772,8 +2784,11 @@ nbctl_dhcp_options_set_options(struct ctl_context *ctx)
static void
nbctl_dhcp_options_get_options(struct ctl_context *ctx)
{
- const struct nbrec_dhcp_options *dhcp_opts = dhcp_options_get(
- ctx, ctx->argv[1], true);
+ const struct nbrec_dhcp_options *dhcp_opts;
+ char *error = dhcp_options_get(ctx, ctx->argv[1], true, &dhcp_opts);
+ if (error) {
+ ctl_fatal("%s", error);
+ }
struct smap_node *node;
SMAP_FOR_EACH(node, &dhcp_opts->options) {
@@ -2788,7 +2803,10 @@ nbctl_dhcp_options_del(struct ctl_context *ctx)
const char *id = ctx->argv[1];
const struct nbrec_dhcp_options *dhcp_opts;
- dhcp_opts = dhcp_options_get(ctx, id, must_exist);
+ char *error = dhcp_options_get(ctx, id, must_exist, &dhcp_opts);
+ if (error) {
+ ctl_fatal("%s", error);
+ }
if (!dhcp_opts) {
return;
}