Update nft_run_cmd_from_filename() to use this new helper function. Move err: tag to a later stage, which is run by the variables defined via --define option, this should be safe. No functional changes are intended, this comes in preparation to support several list/reset commands in a batch. Signed-off-by: Pablo Neira Ayuso --- src/libnftables.c | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/src/libnftables.c b/src/libnftables.c index 5471ccf6f789..987f5d73ade4 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -761,9 +761,9 @@ static struct error_record *filename_is_useable(struct nft_ctx *nft, const char static int __nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename) { struct error_record *erec; - int rc, parser_rc; LIST_HEAD(msgs); LIST_HEAD(cmds); + int rc; erec = filename_is_useable(nft, filename); if (erec) { @@ -782,35 +782,17 @@ static int __nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename if (rc == -EINVAL) rc = nft_parse_bison_filename(nft, filename, &msgs, &cmds); - parser_rc = rc; - if (nft->optimize_flags) nft_optimize(nft, &cmds); - rc = nft_evaluate(nft, &msgs, &cmds); - if (rc < 0) { - if (errno == EPERM) { - fprintf(stderr, "%s (you must be root)\n", - strerror(errno)); - } - goto err; - } - - if (parser_rc) { - rc = parser_rc; - goto err; - } - - if (nft_netlink(nft, &cmds, &msgs) != 0) - rc = -1; -err: - nft_run_cmd_release(nft, &msgs, &cmds); + rc = nft_eval_run_cmds(nft, &msgs, &cmds, rc); iface_cache_release(); if (nft->scanner) { scanner_destroy(nft); nft->scanner = NULL; } +err: if (!list_empty(&nft->vars_ctx.indesc_list)) { struct input_descriptor *indesc, *next; @@ -821,15 +803,8 @@ err: free(indesc); } } - free_const(nft->vars_ctx.buf); - - if (!rc && - nft_output_json(&nft->output) && - nft_output_echo(&nft->output)) - json_print_echo(nft); - if (rc || nft->check) - nft_cache_release(&nft->cache); + free_const(nft->vars_ctx.buf); scope_release(nft->state->scopes[0]); -- 2.47.3