Then show_perror print function outputs the message with a va_list.
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
obj_print(r);
}
-static void json_output_perror(const char *msg)
+static void json_output_perror(const char *msg, va_list ap)
{
struct json_object *r = json_create_object();
_cleanup_free_ char *error = NULL;
- if (asprintf(&error, "%s: %s", msg, strerror(errno)) < 0)
+ if (vasprintf(&error, msg, ap) < 0)
error = "Could not allocate string";
- obj_add_str(r, "error", error);
+ obj_add_key(r, "error", "%s: %s", error, strerror(errno));
json_output_object(r);
}
fprintf(error ? stderr : stdout, "\n");
}
-static void stdout_perror(const char *msg)
+static void stdout_perror(const char *msg, va_list ap)
{
- perror(msg);
+ _cleanup_free_ char *error = NULL;
+
+ if (vasprintf(&error, msg, ap) < 0)
+ error = "Could not allocate string";
+
+ perror(error);
}
static void stdout_discovery_log(struct nvmf_discovery_log *log, int numrec)
va_end(ap);
}
-void nvme_show_perror(const char *msg)
+void nvme_show_perror(const char *msg, ...)
{
struct print_ops *ops = nvme_print_ops(NORMAL);
+ va_list ap;
+
+ va_start(ap, msg);
if (nvme_is_output_format_json())
ops = nvme_print_ops(JSON);
if (ops && ops->show_perror)
- ops->show_perror(msg);
+ ops->show_perror(msg, ap);
+
+ va_end(ap);
}
void nvme_show_discovery_log(struct nvmf_discovery_log *log, uint64_t numrec,
/* status and error messages */
void (*connect_msg)(nvme_ctrl_t c);
void (*show_message)(bool error, const char *msg, va_list ap);
- void (*show_perror)(const char *msg);
+ void (*show_perror)(const char *msg, va_list ap);
void (*show_status)(int status);
void (*show_error_status)(int status, const char *msg, va_list ap);
void nvme_dev_full_path(nvme_ns_t n, char *path, size_t len);
void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len);
void nvme_show_message(bool error, const char *msg, ...);
-void nvme_show_perror(const char *msg);
+void nvme_show_perror(const char *msg, ...);
void nvme_show_error_status(int status, const char *msg, ...);
void nvme_show_init(void);
void nvme_show_finish(void);