From 1be5e6f808e3908ecd13ab68b3fea0739794f02d Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 20 Nov 2017 16:54:04 +0100 Subject: libnftables: Ensure output_fp is never NULL Initialize output_fp to 'stdout' upon context creation and check output stream validity in nft_ctx_set_output(). This allows to drop checks in nft_{gmp_,}print() and do_command_export(). While doing so for the latter, simplify it a bit by using nft_print() which takes care of flushing the output stream. If applications desire to drop all output, they are supposed to open /dev/null and assign that. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/rule.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/rule.c') diff --git a/src/rule.c b/src/rule.c index eb91be46..37d99c22 100644 --- a/src/rule.c +++ b/src/rule.c @@ -1153,9 +1153,6 @@ static int do_command_export(struct netlink_ctx *ctx, struct cmd *cmd) struct nftnl_ruleset *rs; FILE *fp = ctx->octx->output_fp; - if (!fp) - return 0; - do { rs = netlink_dump_ruleset(ctx, &cmd->handle, &cmd->location); if (rs == NULL && errno != EINTR) @@ -1163,8 +1160,7 @@ static int do_command_export(struct netlink_ctx *ctx, struct cmd *cmd) } while (rs == NULL); nftnl_ruleset_fprintf(fp, rs, cmd->export->format, 0); - fprintf(fp, "\n"); - fflush(fp); + nft_print(ctx->octx, "\n"); nftnl_ruleset_free(rs); return 0; -- cgit v1.2.3