Skip to contentSkip to conversation

Follow-up on nft_print() enhancement

PATCH Applied Phil Sutter 2 participants 4 messages Sep 29, 2017 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

cover Follow-up on nft_print() enhancement

This fixes two spots I forgot to clean up before submitting the patches.

Phil Sutter (2):
main: Flush output from nft_gmp_print()
main: Drop stdout hack to expose nft_print() implementation issues

 src/main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Signature · 1 line
2.13.1
author reviewer
#1 lore raw

PATCH 1/2 main: Flush output from nft_gmp_print()

This adds a missing call to fflush() to nft_gmp_print() just like in nft_print(). This is strictly not necessary since usually nft_gmp_print() is followed by a call to nft_print() but better not rely upon this assumption.

---
 src/main.c | 1 +
 1 file changed, 1 insertion(+)
src/main.c +1 -0
index 079a05b80e511..6d2422ffeccf9 100644
@@ -403,6 +403,7 @@ int nft_gmp_print(struct output_ctx *octx, const char *fmt, ...)
 	va_start(arg, fmt);
 	ret = gmp_vfprintf(octx->output_fp, fmt, arg);
 	va_end(arg);
+	fflush(octx->output_fp);
 
 	return ret;
 }
Signature · 1 line
2.13.1
author reviewer
#2 lore raw

PATCH 2/2 main: Drop stdout hack to expose nft_print() implementation issues

In reply to Phil Sutter

This was helpful when testing nft_print() implementation, but breaks 'nft --help' output. Also, with this in place typical printf-debugging would have to use stderr at all times which is confusing at least.

---
 src/main.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
src/main.c +1 -3
index 6d2422ffeccf9..fc79cfaa30e0c 100644
@@ -415,11 +415,9 @@ int main(int argc, char * const *argv)
 	bool interactive = false;
 	struct parser_state state;
 	int i, val, rc;
-	FILE *outfp = fdopen(dup(STDOUT_FILENO), "w");
 
 	nft = nft_ctx_new(NFT_CTX_DEFAULT);
-	nft_ctx_set_output(nft, outfp);
-	close(STDOUT_FILENO);
+	nft_ctx_set_output(nft, stdout);
 
 	while (1) {
 		val = getopt_long(argc, argv, OPTSTRING, options, NULL);
Signature · 1 line
2.13.1