Blame SOURCES/0101-util-json-Warn-on-stderr-about-empty-list-results.patch

2eb93d
From 91f78bbcda7fc644041dfabfa679c6a627f90e76 Mon Sep 17 00:00:00 2001
2eb93d
From: Dan Williams <dan.j.williams@intel.com>
2eb93d
Date: Sun, 23 Jan 2022 16:53:08 -0800
2eb93d
Subject: [PATCH 101/217] util/json: Warn on stderr about empty list results
2eb93d
2eb93d
Help interactive users notice something is wrong with the list parameters
2eb93d
by warning that no devices matched the specified filter settings.
2eb93d
2eb93d
Link: https://lore.kernel.org/r/164298558814.3021641.13051269428355986099.stgit@dwillia2-desk3.amr.corp.intel.com
2eb93d
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 util/json.c | 7 +++++--
2eb93d
 1 file changed, 5 insertions(+), 2 deletions(-)
2eb93d
2eb93d
diff --git a/util/json.c b/util/json.c
2eb93d
index bd5f8fc..f8cc81f 100644
2eb93d
--- a/util/json.c
2eb93d
+++ b/util/json.c
2eb93d
@@ -3,6 +3,7 @@
2eb93d
 #include <limits.h>
2eb93d
 #include <string.h>
2eb93d
 #include <stdio.h>
2eb93d
+#include <util/util.h>
2eb93d
 #include <util/json.h>
2eb93d
 #include <json-c/json.h>
2eb93d
 #include <json-c/printbuf.h>
2eb93d
@@ -95,9 +96,11 @@ void util_display_json_array(FILE *f_out, struct json_object *jarray,
2eb93d
 	int len = json_object_array_length(jarray);
2eb93d
 	int jflag = JSON_C_TO_STRING_PRETTY;
2eb93d
 
2eb93d
-	if (json_object_array_length(jarray) > 1 || !(flags & UTIL_JSON_HUMAN))
2eb93d
+	if (len > 1 || !(flags & UTIL_JSON_HUMAN)) {
2eb93d
+		if (len == 0)
2eb93d
+			warning("no matching devices found\n");
2eb93d
 		fprintf(f_out, "%s\n", json_object_to_json_string_ext(jarray, jflag));
2eb93d
-	else if (len) {
2eb93d
+	} else if (len) {
2eb93d
 		struct json_object *jobj;
2eb93d
 
2eb93d
 		jobj = json_object_array_get_idx(jarray, 0);
2eb93d
-- 
2eb93d
2.27.0
2eb93d