Skip to contentSkip to conversation

Improve a few minor JSON glitches

PATCH Applied Phil Sutter 2 participants 4 messages Jun 24, 2019 – Jun 25, 2019 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

cover Improve a few minor JSON glitches

As suggested offline, print newline at end of JSON output (patch 1) and don't ignore -j flag if JSON support is not compiled-in - bail instead (patch 2).

Phil Sutter (2):
json: Print newline at end of list output
main: Bail if non-available JSON was requested

 src/json.c | 2 ++
 src/main.c | 3 +++
 2 files changed, 5 insertions(+)
Signature · 1 line
2.21.0
author reviewer
#1 lore raw

PATCH 1/2 json: Print newline at end of list output

If listing ruleset elements with '-j' flag, print a final newline to not upset shell prompts.

---
 src/json.c | 2 ++
 1 file changed, 2 insertions(+)
src/json.c +2 -0
index 4e64684201638..1484c21be819a 100644
@@ -1752,6 +1752,8 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
 	root = json_pack("{s:o}", "nftables", root);
 	json_dumpf(root, ctx->nft->output.output_fp, 0);
 	json_decref(root);
+	fprintf(ctx->nft->output.output_fp, "\n");
+	fflush(ctx->nft->output.output_fp);
 	return 0;
 }
 
Signature · 1 line
2.21.0
author reviewer
#2 lore raw

PATCH 2/2 main: Bail if non-available JSON was requested

In reply to Phil Sutter

If user passes '-j' flag, falling back to standard syntax output probably causes more harm than good so instead print an error message and exit(1).

---
 src/main.c | 3 +++
 1 file changed, 3 insertions(+)
src/main.c +3 -0
index 9a50f30f850b2..cbfd69a42d045 100644
@@ -277,6 +277,9 @@ int main(int argc, char * const *argv)
 		case OPT_JSON:
 #ifdef HAVE_LIBJANSSON
 			output_flags |= NFT_CTX_OUTPUT_JSON;
+#else
+			fprintf(stderr, "JSON support not compiled-in\n");
+			exit(EXIT_FAILURE);
 #endif
 			break;
 		case OPT_GUID:
Signature · 1 line
2.21.0
maintainer Applied
#3 lore raw
In reply to Phil Sutter
Quoted 3 lines · Phil Sutter

As suggested offline, print newline at end of JSON output (patch 1) and don't ignore -j flag if JSON support is not compiled-in - bail instead (patch 2).

Applied.