anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

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

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