From 9200bfc50653612033d58774f422fc20150d3301 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 13 Nov 2017 15:08:16 +0100 Subject: libnftables: Unexport enum nftables_exit_codes Apart from SUCCESS/FAILURE, these codes were not used by library functions simply because NOMEM and NONL conditions lead to calling exit() instead of propagating the error condition back up the call stack. Instead, make nft_run_cmd_from_*() return either 0 or -1 on error. Usually errno will then contain more details about what happened and/or there are messages in erec. Calls to exit()/return in main() are adjusted to stay compatible. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/libnftables.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libnftables.c') diff --git a/src/libnftables.c b/src/libnftables.c index dc6a5fdf..e8fa6742 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -272,7 +272,7 @@ static const struct input_descriptor indesc_cmdline = { int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen) { - int rc = NFT_EXIT_SUCCESS; + int rc = 0; struct parser_state state; LIST_HEAD(msgs); void *scanner; @@ -284,7 +284,7 @@ int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen) scanner_push_buffer(scanner, &indesc_cmdline, buf); if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0) - rc = NFT_EXIT_FAILURE; + rc = -1; fp = nft_ctx_set_output(nft, stderr); erec_print_list(&nft->output, &msgs, nft->debug_mask); @@ -306,18 +306,18 @@ int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename) rc = cache_update(nft->nf_sock, &nft->cache, CMD_INVALID, &msgs, nft->debug_mask, &nft->output); if (rc < 0) - return NFT_EXIT_FAILURE; + return -1; parser_init(nft->nf_sock, &nft->cache, &state, &msgs, nft->debug_mask, &nft->output); scanner = scanner_init(&state); if (scanner_read_file(scanner, filename, &internal_location) < 0) { - rc = NFT_EXIT_FAILURE; + rc = -1; goto err; } if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0) - rc = NFT_EXIT_FAILURE; + rc = -1; err: fp = nft_ctx_set_output(nft, stderr); erec_print_list(&nft->output, &msgs, nft->debug_mask); -- cgit v1.2.3