Skip to content

Commit

Permalink
db-ctl-base: Don't die in pre_get_table() on error.
Browse files Browse the repository at this point in the history
Return the error message to the caller instead of reporting it and dying
so that the caller can handle the error without terminating the process
if needed.

Signed-off-by: Jakub Sitnicki <jkbs@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
Jakub Sitnicki authored and blp committed Jul 3, 2018
1 parent 87e2227 commit c835e58
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/db-ctl-base.c
Expand Up @@ -479,11 +479,15 @@ pre_get_column(struct ctl_context *ctx,
return NULL;
}

static const struct ovsdb_idl_table_class *
pre_get_table(struct ctl_context *ctx, const char *table_name)
static char * OVS_WARN_UNUSED_RESULT
pre_get_table(struct ctl_context *ctx, const char *table_name,
const struct ovsdb_idl_table_class **tablep)
{
const struct ovsdb_idl_table_class *table;
die_if_error(get_table(table_name, &table));
char *error = get_table(table_name, &table);
if (error) {
return error;
}
ovsdb_idl_add_table(ctx->idl, table);

const struct ctl_table_class *ctl = &ctl_classes[table - idl_classes];
Expand All @@ -497,7 +501,10 @@ pre_get_table(struct ctl_context *ctx, const char *table_name)
}
}

return table;
if (tablep) {
*tablep = table;
}
return NULL;
}

static char *
Expand Down Expand Up @@ -868,7 +875,7 @@ pre_cmd_get(struct ctl_context *ctx)
"possibly erroneous");
}

table = pre_get_table(ctx, table_name);
die_if_error(pre_get_table(ctx, table_name, &table));
for (i = 3; i < ctx->argc; i++) {
if (!strcasecmp(ctx->argv[i], "_uuid")
|| !strcasecmp(ctx->argv[i], "-uuid")) {
Expand Down Expand Up @@ -1054,7 +1061,7 @@ pre_cmd_list(struct ctl_context *ctx)
const char *table_name = ctx->argv[1];
const struct ovsdb_idl_table_class *table;

table = pre_get_table(ctx, table_name);
die_if_error(pre_get_table(ctx, table_name, &table));
pre_list_columns(ctx, table, column_names);
}

Expand Down Expand Up @@ -1186,7 +1193,7 @@ pre_cmd_find(struct ctl_context *ctx)
const struct ovsdb_idl_table_class *table;
int i;

table = pre_get_table(ctx, table_name);
die_if_error(pre_get_table(ctx, table_name, &table));
pre_list_columns(ctx, table, column_names);
for (i = 2; i < ctx->argc; i++) {
pre_parse_column_key_value(ctx, ctx->argv[i], table);
Expand Down Expand Up @@ -1309,7 +1316,7 @@ pre_cmd_set(struct ctl_context *ctx)
const struct ovsdb_idl_table_class *table;
int i;

table = pre_get_table(ctx, table_name);
die_if_error(pre_get_table(ctx, table_name, &table));
for (i = 3; i < ctx->argc; i++) {
pre_parse_column_key_value(ctx, ctx->argv[i], table);
}
Expand Down Expand Up @@ -1346,7 +1353,7 @@ pre_cmd_add(struct ctl_context *ctx)
const struct ovsdb_idl_table_class *table;
const struct ovsdb_idl_column *column;

table = pre_get_table(ctx, table_name);
die_if_error(pre_get_table(ctx, table_name, &table));
die_if_error(pre_get_column(ctx, table, column_name, &column));
}

Expand Down Expand Up @@ -1407,7 +1414,7 @@ pre_cmd_remove(struct ctl_context *ctx)
const struct ovsdb_idl_table_class *table;
const struct ovsdb_idl_column *column;

table = pre_get_table(ctx, table_name);
die_if_error(pre_get_table(ctx, table_name, &table));
die_if_error(pre_get_column(ctx, table, column_name, &column));
}

Expand Down Expand Up @@ -1479,7 +1486,7 @@ pre_cmd_clear(struct ctl_context *ctx)
const struct ovsdb_idl_table_class *table;
int i;

table = pre_get_table(ctx, table_name);
die_if_error(pre_get_table(ctx, table_name, &table));
for (i = 3; i < ctx->argc; i++) {
const struct ovsdb_idl_column *column;

Expand Down Expand Up @@ -1603,7 +1610,7 @@ pre_cmd_destroy(struct ctl_context *ctx)
{
const char *table_name = ctx->argv[1];

pre_get_table(ctx, table_name);
die_if_error(pre_get_table(ctx, table_name, NULL));
}

static void
Expand Down Expand Up @@ -1656,7 +1663,7 @@ pre_cmd_wait_until(struct ctl_context *ctx)
const struct ovsdb_idl_table_class *table;
int i;

table = pre_get_table(ctx, table_name);
die_if_error(pre_get_table(ctx, table_name, &table));

for (i = 3; i < ctx->argc; i++) {
pre_parse_column_key_value(ctx, ctx->argv[i], table);
Expand Down

0 comments on commit c835e58

Please sign in to comment.