]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
json: Print warnings to stderr rather than stdout
authorKerin Millar <kfm@plushkava.net>
Tue, 9 Mar 2021 15:28:45 +0000 (15:28 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 8 Jun 2021 22:22:15 +0000 (00:22 +0200)
Unsurprisingly, printing warnings to stdout results in malformed JSON.

Signed-off-by: Kerin Millar <kfm@plushkava.net>
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1511
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/json.c

index b08c004ae9c94e71ba4ecce1a5da3e6b24c90605..f648ea1b8c1784392af389eae11a671f0552d7c2 100644 (file)
@@ -1,4 +1,5 @@
 #define _GNU_SOURCE
+#include <stdio.h>
 #include <string.h>
 
 #include <expression.h>
@@ -42,7 +43,8 @@ static json_t *expr_print_json(const struct expr *expr, struct output_ctx *octx)
        if (ops->json)
                return ops->json(expr, octx);
 
-       printf("warning: expr ops %s have no json callback\n", expr_name(expr));
+       fprintf(stderr, "warning: expr ops %s have no json callback\n",
+               expr_name(expr));
 
        fp = octx->output_fp;
        octx->output_fp = fmemopen(buf, 1024, "w");
@@ -180,8 +182,8 @@ static json_t *stmt_print_json(const struct stmt *stmt, struct output_ctx *octx)
        if (stmt->ops->json)
                return stmt->ops->json(stmt, octx);
 
-       printf("warning: stmt ops %s have no json callback\n",
-              stmt->ops->name);
+       fprintf(stderr, "warning: stmt ops %s have no json callback\n",
+               stmt->ops->name);
 
        fp = octx->output_fp;
        octx->output_fp = fmemopen(buf, 1024, "w");