From ec5303e1eb26750155b663ae1e0df3f349002ac0 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 22 May 2023 00:54:02 +0900 Subject: [PATCH] nvme-print: Add nvme show result function Signed-off-by: Tokunori Ikegami --- nvme-print.c | 9 ++++++--- nvme-print.h | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nvme-print.c b/nvme-print.c index 4374b43c..7a7f4a53 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -5457,18 +5457,21 @@ void nvme_show_topology(nvme_root_t r, enum nvme_print_flags flags, nvme_show_simple_topology(r, ranking); } -void nvme_show_error(const char *msg, ...) +void nvme_show_message(bool error, const char *msg, ...) { va_list ap; va_start(ap, msg); if (argconfig_output_format_json(false)) { - json_output_error(msg, ap); + if (error) + json_output_error(msg, ap); + else + json_output_result(msg, ap); va_end(ap); return; } - vfprintf(stderr, msg, ap); + vfprintf(error ? stderr : stdout, msg, ap); printf("\n"); diff --git a/nvme-print.h b/nvme-print.h index 25344da8..4c7e58b2 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -13,6 +13,9 @@ typedef struct nvme_effects_log_node { struct list_node node; } nvme_effects_log_node_t; +#define nvme_show_error(msg, ...) nvme_show_message(true, msg, ##__VA_ARGS__) +#define nvme_show_result(msg, ...) nvme_show_message(false, msg, ##__VA_ARGS__) + void d(unsigned char *buf, int len, int width, int group); void d_raw(unsigned char *buf, unsigned len); @@ -155,7 +158,7 @@ char *zone_state_to_string(__u8 state); const char *nvme_pel_event_to_string(int type); const char *get_sanitize_log_sstat_status_str(__u16 status); const char *nvme_ana_state_to_string(enum nvme_ana_state state); -void nvme_show_error(const char *msg, ...); +void nvme_show_message(bool error, const char *msg, ...); void nvme_show_perror(const char *msg); #endif -- 2.49.0