diff mbox series

[iproute2] bridge/mdb: fix missing new line when show bridge mdb

Message ID 1536118423-20604-1-git-send-email-liuhangbin@gmail.com
State Changes Requested, archived
Delegated to: stephen hemminger
Headers show
Series [iproute2] bridge/mdb: fix missing new line when show bridge mdb | expand

Commit Message

Hangbin Liu Sept. 5, 2018, 3:33 a.m. UTC
The bridge mdb show is broken on current iproute2. e.g.
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp 34: br0  veth0_br  224.1.1.1  temp

After fix:
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp
34: br0  veth0_br  224.1.1.1  temp

Reported-by: Ying Xu <yinxu@redhat.com>
Fixes: c7c1a1ef51aea ("bridge: colorize output and use JSON print library")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 bridge/mdb.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Stephen Hemminger Sept. 6, 2018, 1 p.m. UTC | #1
On Wed,  5 Sep 2018 11:33:43 +0800
Hangbin Liu <liuhangbin@gmail.com> wrote:

> The bridge mdb show is broken on current iproute2. e.g.
> ]# bridge mdb show
> 34: br0  veth0_br  224.1.1.2  temp 34: br0  veth0_br  224.1.1.1  temp
> 
> After fix:
> ]# bridge mdb show
> 34: br0  veth0_br  224.1.1.2  temp
> 34: br0  veth0_br  224.1.1.1  temp
> 
> Reported-by: Ying Xu <yinxu@redhat.com>
> Fixes: c7c1a1ef51aea ("bridge: colorize output and use JSON print library")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  bridge/mdb.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/bridge/mdb.c b/bridge/mdb.c
> index f38dc67..d89c065 100644
> --- a/bridge/mdb.c
> +++ b/bridge/mdb.c
> @@ -107,6 +107,10 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr,
>  			fprintf(f, "%s ", port_ifname);
>  		}
>  	}
> +
> +	if (!is_json_context() && !show_stats)
> +		fprintf(f, "\n");
> +
>  	close_json_array(PRINT_JSON, NULL);
>  }
>  
> @@ -164,6 +168,10 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
>  		print_string(PRINT_ANY, "timer", " %s",
>  			     format_timer(timer));
>  	}
> +
> +	if (!is_json_context())
> +		fprintf(f, "\n");
> +
>  	close_json_object();
>  }
>  

Thanks for catching this.

Now that there is a json print library, the preferred pattern for
this is:
	print_string(PRINT_FP, NULL, "\n", NULL);

I plan to introduce a helper
	print_fp(...)

and it would be easier if all places were consistent.
Hangbin Liu Sept. 7, 2018, 12:14 a.m. UTC | #2
Hi Stephen,
On Thu, Sep 06, 2018 at 02:00:53PM +0100, Stephen Hemminger wrote:
> > @@ -164,6 +168,10 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
> >  		print_string(PRINT_ANY, "timer", " %s",
> >  			     format_timer(timer));
> >  	}
> > +
> > +	if (!is_json_context())
> > +		fprintf(f, "\n");
> > +
> >  	close_json_object();
> >  }
> >  
> 
> Thanks for catching this.
> 
> Now that there is a json print library, the preferred pattern for
> this is:
> 	print_string(PRINT_FP, NULL, "\n", NULL);

Are we going to replace all printf() by json print library, even not in
json context? If yes, I can post a v2 patch. Becuase there are still a
lot fprintf() in mdb.c.

> 
> I plan to introduce a helper
> 	print_fp(...)
> 
> and it would be easier if all places were consistent.

cool, that would be more clear.

Thanks
Hangbin
diff mbox series

Patch

diff --git a/bridge/mdb.c b/bridge/mdb.c
index f38dc67..d89c065 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -107,6 +107,10 @@  static void br_print_router_ports(FILE *f, struct rtattr *attr,
 			fprintf(f, "%s ", port_ifname);
 		}
 	}
+
+	if (!is_json_context() && !show_stats)
+		fprintf(f, "\n");
+
 	close_json_array(PRINT_JSON, NULL);
 }
 
@@ -164,6 +168,10 @@  static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
 		print_string(PRINT_ANY, "timer", " %s",
 			     format_timer(timer));
 	}
+
+	if (!is_json_context())
+		fprintf(f, "\n");
+
 	close_json_object();
 }