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

Anton Tykhyy atykhyy at gmail.com
Wed Feb 12 12:08:02 CET 2020


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



More information about the drbd-user mailing list