Blame SOURCES/0006-monitor-Make-JSON-XML-output-respect-output_fp.patch

a05102
From fa5ccccd164b7285c4d105265ece4ea7ccdd996a Mon Sep 17 00:00:00 2001
a05102
From: Phil Sutter <psutter@redhat.com>
a05102
Date: Wed, 20 Jun 2018 09:22:00 +0200
a05102
Subject: [PATCH] monitor: Make JSON/XML output respect output_fp
a05102
a05102
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1504157
a05102
Upstream Status: nftables commit 59034b47590d7
a05102
a05102
commit 59034b47590d7cd19ba2fda24bf4426c355f95bc
a05102
Author: Phil Sutter <phil@nwl.cc>
a05102
Date:   Wed Feb 28 16:04:28 2018 +0100
a05102
a05102
    monitor: Make JSON/XML output respect output_fp
a05102
a05102
    Make sure events callbacks print to output_ctx-defined stream for any
a05102
    type of output format.
a05102
a05102
    Since all of them use nft_print() as last call (if anything is printed
a05102
    at all), the final call to fflush() in netlink_events_cb() can be
a05102
    dropped.
a05102
a05102
    Signed-off-by: Phil Sutter <phil@nwl.cc>
a05102
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
a05102
---
a05102
 src/netlink.c | 37 ++++++++++++++++++-------------------
a05102
 1 file changed, 18 insertions(+), 19 deletions(-)
a05102
a05102
diff --git a/src/netlink.c b/src/netlink.c
a05102
index d839ded..ca0e207 100644
a05102
--- a/src/netlink.c
a05102
+++ b/src/netlink.c
a05102
@@ -2015,9 +2015,9 @@ static int netlink_events_table_cb(const struct nlmsghdr *nlh, int type,
a05102
 		break;
a05102
 	case NFTNL_OUTPUT_XML:
a05102
 	case NFTNL_OUTPUT_JSON:
a05102
-		nftnl_table_fprintf(stdout, nlt, monh->format,
a05102
-				    netlink_msg2nftnl_of(type));
a05102
-		fprintf(stdout, "\n");
a05102
+		nftnl_table_fprintf(monh->ctx->octx->output_fp, nlt,
a05102
+				    monh->format, netlink_msg2nftnl_of(type));
a05102
+		nft_mon_print(monh, "\n");
a05102
 		break;
a05102
 	}
a05102
 
a05102
@@ -2057,9 +2057,9 @@ static int netlink_events_chain_cb(const struct nlmsghdr *nlh, int type,
a05102
 		break;
a05102
 	case NFTNL_OUTPUT_XML:
a05102
 	case NFTNL_OUTPUT_JSON:
a05102
-		nftnl_chain_fprintf(stdout, nlc, monh->format,
a05102
-				    netlink_msg2nftnl_of(type));
a05102
-		fprintf(stdout, "\n");
a05102
+		nftnl_chain_fprintf(monh->ctx->octx->output_fp, nlc,
a05102
+				    monh->format, netlink_msg2nftnl_of(type));
a05102
+		nft_mon_print(monh, "\n");
a05102
 		break;
a05102
 	}
a05102
 
a05102
@@ -2104,9 +2104,9 @@ static int netlink_events_set_cb(const struct nlmsghdr *nlh, int type,
a05102
 		break;
a05102
 	case NFTNL_OUTPUT_XML:
a05102
 	case NFTNL_OUTPUT_JSON:
a05102
-		nftnl_set_fprintf(stdout, nls, monh->format,
a05102
-				netlink_msg2nftnl_of(type));
a05102
-		fprintf(stdout, "\n");
a05102
+		nftnl_set_fprintf(monh->ctx->octx->output_fp, nls,
a05102
+				  monh->format, netlink_msg2nftnl_of(type));
a05102
+		nft_mon_print(monh, "\n");
a05102
 		break;
a05102
 	}
a05102
 out:
a05102
@@ -2253,9 +2253,9 @@ static int netlink_events_setelem_cb(const struct nlmsghdr *nlh, int type,
a05102
 		break;
a05102
 	case NFTNL_OUTPUT_XML:
a05102
 	case NFTNL_OUTPUT_JSON:
a05102
-		nftnl_set_fprintf(stdout, nls, monh->format,
a05102
-				  netlink_msg2nftnl_of(type));
a05102
-		fprintf(stdout, "\n");
a05102
+		nftnl_set_fprintf(monh->ctx->octx->output_fp, nls,
a05102
+				  monh->format, netlink_msg2nftnl_of(type));
a05102
+		nft_mon_print(monh, "\n");
a05102
 		break;
a05102
 	}
a05102
 out:
a05102
@@ -2298,9 +2298,9 @@ static int netlink_events_obj_cb(const struct nlmsghdr *nlh, int type,
a05102
 		break;
a05102
 	case NFTNL_OUTPUT_XML:
a05102
 	case NFTNL_OUTPUT_JSON:
a05102
-		nftnl_obj_fprintf(stdout, nlo, monh->format,
a05102
-				  netlink_msg2nftnl_of(type));
a05102
-		fprintf(stdout, "\n");
a05102
+		nftnl_obj_fprintf(monh->ctx->octx->output_fp, nlo,
a05102
+				  monh->format, netlink_msg2nftnl_of(type));
a05102
+		nft_mon_print(monh, "\n");
a05102
 		break;
a05102
 	}
a05102
 
a05102
@@ -2354,9 +2354,9 @@ static int netlink_events_rule_cb(const struct nlmsghdr *nlh, int type,
a05102
 		break;
a05102
 	case NFTNL_OUTPUT_XML:
a05102
 	case NFTNL_OUTPUT_JSON:
a05102
-		nftnl_rule_fprintf(stdout, nlr, monh->format,
a05102
-				 netlink_msg2nftnl_of(type));
a05102
-		fprintf(stdout, "\n");
a05102
+		nftnl_rule_fprintf(monh->ctx->octx->output_fp, nlr,
a05102
+				   monh->format, netlink_msg2nftnl_of(type));
a05102
+		nft_mon_print(monh, "\n");
a05102
 		break;
a05102
 	}
a05102
 
a05102
@@ -2985,7 +2985,6 @@ static int netlink_events_cb(const struct nlmsghdr *nlh, void *data)
a05102
 		ret = netlink_events_newgen_cb(nlh, type, monh);
a05102
 		break;
a05102
 	}
a05102
-	fflush(stdout);
a05102
 
a05102
 	return ret;
a05102
 }
a05102
-- 
a05102
1.8.3.1
a05102