[DRBD-user] [PATCH] Fixes malformed json output of drbdsetup show for an empty resource.

Roland Kammerer roland.kammerer at linbit.com
Wed Feb 12 14:34:45 CET 2020


On Wed, Feb 12, 2020 at 02:02:12PM +0100, Roland Kammerer wrote:
> On Wed, Feb 12, 2020 at 01:52:44PM +0100, Roland Kammerer wrote:
> > On Wed, Feb 12, 2020 at 01:08:02PM +0200, Anton Tykhyy wrote:
> > > To reproduce the bug:
> > > >> drbdsetup new-resource test 0; drbdsetup show --json|jq
> > > > parse error: Expected separator between values at line 6, column 21
> > > ---
> > >  user/v9/drbdsetup.c | 15 +++++++++------
> > >  1 file changed, 9 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/user/v9/drbdsetup.c b/user/v9/drbdsetup.c
> > > index de752484..4798cf62 100644
> > > --- a/user/v9/drbdsetup.c
> > > +++ b/user/v9/drbdsetup.c
> > > @@ -2401,13 +2401,16 @@ static void show_resource_list_json(struct resources_list *resources_list, char*
> > >  			printf("\n");
> > >  		}
> > >  
> > > -		printI(QUOTED("volumes") ": [\n");
> > > -		indent++;
> > > -		for (device = devices; device; device = device->next)
> > > -			show_volume_json(device);
> > > +		if (devices)
> > > +		{
> > > +			printI(QUOTED("volumes") ": [\n");
> > > +			indent++;
> > > +			for (device = devices; device; device = device->next)
> > > +				show_volume_json(device);
> > >  
> > > -		--indent;
> > > -		printI("]\n");
> > > +			--indent;
> > > +			printI("]\n");
> > > +		}
> > >  
> > >  		--indent;
> > >  		printI("}");
> > > -- 
> > > 2.21.0.windows.1
> > 
> > Hi Anton,
> > 
> > pretty obscure use case, but LGTM at a first glance :)
> 
> Nah, it does not. The problem is not printing an ',', not the empty
> volumes section. Anyways, thanks, I will prepare a proper fix for that.

I'd say this is the actual fix.

Anthony, can you check this also fixes your use case? If we always print
the volumes (potentually [], which is fine and I like better), then we
should just always print the ',' preceding the volumes section.

diff --git a/user/v9/drbdsetup.c b/user/v9/drbdsetup.c
index de752484..765b3be9 100644
--- a/user/v9/drbdsetup.c
+++ b/user/v9/drbdsetup.c
@@ -2394,12 +2394,7 @@ static void show_resource_list_json(struct resources_list *resources_list, char*

                nla = nla_find_nested(resource->res_opts, __nla_type(T_node_id));
                if (nla)
-               {
-                       printI("\"node-id\": %d", *(uint32_t *)nla_data(nla));
-                       if (devices)
-                               printf(",");
-                       printf("\n");
-               }
+                       printI("\"node-id\": %d,\n", *(uint32_t *)nla_data(nla));

                printI(QUOTED("volumes") ": [\n");
                indent++;



More information about the drbd-user mailing list