diff options
author | Phil Sutter <phil@nwl.cc> | 2018-04-10 19:00:21 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-04-11 09:57:28 +0200 |
commit | 4176e24e14f0723486253ebcfd2885c77f82f7b1 (patch) | |
tree | f568b8ff2c2ca0a68e3ef1085e7dcb291a694bb6 /src/libnftables.c | |
parent | 2b3f18e0cf7a7914b500cf17cc47e5bddb9d6848 (diff) |
libnftables: Introduce nft_ctx_set_error()
Analogous to nft_ctx_set_output(), this allows to set a custom file
pointer for writing error messages to.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/libnftables.c')
-rw-r--r-- | src/libnftables.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/libnftables.c b/src/libnftables.c index 8bf989b0..d6622d51 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -169,6 +169,7 @@ struct nft_ctx *nft_ctx_new(uint32_t flags) init_list_head(&ctx->cache.list); ctx->flags = flags; ctx->output.output_fp = stdout; + ctx->output.error_fp = stderr; if (flags == NFT_CTX_DEFAULT) nft_ctx_netlink_init(ctx); @@ -200,6 +201,18 @@ FILE *nft_ctx_set_output(struct nft_ctx *ctx, FILE *fp) return old; } +FILE *nft_ctx_set_error(struct nft_ctx *ctx, FILE *fp) +{ + FILE *old = ctx->output.error_fp; + + if (!fp || ferror(fp)) + return NULL; + + ctx->output.error_fp = fp; + + return old; +} + bool nft_ctx_get_dry_run(struct nft_ctx *ctx) { return ctx->check; @@ -282,7 +295,6 @@ int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen) LIST_HEAD(msgs); size_t nlbuflen; void *scanner; - FILE *fp; char *nlbuf; nlbuflen = max(buflen + 1, strlen(buf) + 2); @@ -297,9 +309,7 @@ int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen) if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0) rc = -1; - fp = nft_ctx_set_output(nft, stderr); erec_print_list(&nft->output, &msgs, nft->debug_mask); - nft_ctx_set_output(nft, fp); scanner_destroy(scanner); iface_cache_release(); free(nlbuf); |