]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
nvme-list: print empty lists when no devices are present
authorKeith Busch <keith.busch@intel.com>
Mon, 8 May 2017 20:48:12 +0000 (16:48 -0400)
committerKeith Busch <keith.busch@intel.com>
Mon, 8 May 2017 20:50:27 +0000 (16:50 -0400)
https://github.com/linux-nvme/nvme-cli/issues/173

Signed-off-by: Keith Busch <keith.busch@intel.com>
nvme-print.c
nvme.c

index b52c26933f79c2b9701dbfe97b014097d02112c3..d28fbe1429f651ccf257e54ef0b002f44c2173f3 100644 (file)
@@ -1149,7 +1149,8 @@ void json_print_list_items(struct list_item *list_items, unsigned len)
                json_array_add_value_object(devices, device_attrs);
                free((void*)product);
        }
-       json_object_add_value_array(root, "Devices", devices);
+       if (i)
+               json_object_add_value_array(root, "Devices", devices);
        json_print_object(root, NULL);
 }
 
diff --git a/nvme.c b/nvme.c
index 4cc5a96d55c5396726823bd94f61e709785e3429..c2196346965e0cacce2ff8200cd16f4a4930f7da 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -834,7 +834,7 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi
                return -EINVAL;
 
        n = scandir(dev, &devices, scan_dev_filter, alphasort);
-       if (n <= 0)
+       if (n < 0)
                return n;
 
        list_items = calloc(n, sizeof(*list_items));