On Fri, 13 Jul 2018 15:23:30 -0700, Stephen Hemminger wrote:
> > > I prefer to not use "printf(fp," and use print_string(PRINT_FP, NULL, 
> > > "%s", ...)
> > > because otherwise you end up mixing strings and json format output in the
> > > same result.
> > > 
> > > You should be able to do
> > >   tc -j ... 
> > > and always get valid JSON output.
> > > 
> > > One quick way to test json validation is to pipe it into python:
> > >   tc -j ... | python -mjson.tool    
> > 
> > Note that XDP has separate print functions for plain text and JSON, and
> > the flow gets separated early on:
> > 
> >     mode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]);
> >     if (mode == XDP_ATTACHED_NONE)
> >             return;
> >     else if (is_json_context())
> >             return details ? (void)0 : xdp_dump_json(tb);
> > 
> >     ... non-JSON handling follows...
> > 
> > The use of fprintfs is therefore okay.  Do you have a preference for
> > using the wrapper, even if fprintf is safe?  It's brevity vs
> > consistency, I guess.  We'd need a separate patch for that, 'cause I'm
> > not touching all the fprintfs in the file, anyway.  
> 
> The only preference for the wrapper is that it is easy way to make
> sure all code is JSON aware.  

Yes...

> Since fp is always stdout in current code, maybe just convert to printf.

...or maybe we could consider adding a wrapper for printf that wouldn't
take all the unnecessary parameters print_string() takes, yet clearly
indicate autor knows about JSON output concerns?

Reply via email to