diff mbox series

[iproute2] ip: mroute: add fflush to print_mroute

Message ID 20190426105421.32139-1-nikolay@cumulusnetworks.com
State Accepted
Delegated to: stephen hemminger
Headers show
Series [iproute2] ip: mroute: add fflush to print_mroute | expand

Commit Message

Nikolay Aleksandrov April 26, 2019, 10:54 a.m. UTC
Similar to other print functions we need to flush buffered data
in order to work with pipes and output redirects.

After this patch ip monitor mroute &>log works properly.

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
 ip/ipmroute.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Stephen Hemminger April 29, 2019, 10:05 p.m. UTC | #1
On Fri, 26 Apr 2019 13:54:21 +0300
Nikolay Aleksandrov <nikolay@cumulusnetworks.com> wrote:

> Similar to other print functions we need to flush buffered data
> in order to work with pipes and output redirects.
> 
> After this patch ip monitor mroute &>log works properly.
> 
> Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> ---
>  ip/ipmroute.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/ip/ipmroute.c b/ip/ipmroute.c
> index b29c78e4cc86..ede09ca96412 100644
> --- a/ip/ipmroute.c
> +++ b/ip/ipmroute.c
> @@ -57,6 +57,7 @@ int print_mroute(struct nlmsghdr *n, void *arg)
>  	struct rtmsg *r = NLMSG_DATA(n);
>  	int len = n->nlmsg_len;
>  	struct rtattr *tb[RTA_MAX+1];
> +	FILE *fp = (FILE *)arg;

Applied, but the cast here is unnecessary in C.
So I removed it.
diff mbox series

Patch

diff --git a/ip/ipmroute.c b/ip/ipmroute.c
index b29c78e4cc86..ede09ca96412 100644
--- a/ip/ipmroute.c
+++ b/ip/ipmroute.c
@@ -57,6 +57,7 @@  int print_mroute(struct nlmsghdr *n, void *arg)
 	struct rtmsg *r = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
 	struct rtattr *tb[RTA_MAX+1];
+	FILE *fp = (FILE *)arg;
 	const char *src, *dst;
 	SPRINT_BUF(b1);
 	SPRINT_BUF(b2);
@@ -209,6 +210,7 @@  int print_mroute(struct nlmsghdr *n, void *arg)
 
 	print_string(PRINT_FP, NULL, "\n", NULL);
 	close_json_object();
+	fflush(fp);
 	return 0;
 }