anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

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

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