aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-09-07 11:45:39 +0400
committerMarc-André Lureau <marcandre.lureau@redhat.com>2018-10-05 16:14:22 +0400
commita95db58f210ddf5ed61f25cfcb89063cda86ea3c (patch)
tree63e813a437c031361127ec22f39acd059de0c234
parentb8e5671a8cd196e7262802ca895bf87d50416989 (diff)
qdev-monitor: print help to stdout
qdev_device_help() is used from command line "-device help", or from HMP "device_add". If used from command line, print help to stdout (it is only printed on explicit demand). Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
-rw-r--r--include/monitor/monitor.h3
-rw-r--r--monitor.c16
-rw-r--r--qdev-monitor.c32
3 files changed, 35 insertions, 16 deletions
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 2ef5e04b37..6fd2c53b09 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -47,4 +47,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
void monitor_fdset_dup_fd_remove(int dup_fd);
int monitor_fdset_dup_fd_find(int dup_fd);
+void monitor_vfprintf(FILE *stream,
+ const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
+
#endif /* MONITOR_H */
diff --git a/monitor.c b/monitor.c
index c4677b502b..b9258a7438 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4493,19 +4493,29 @@ static void monitor_readline_flush(void *opaque)
}
/*
- * Print to current monitor if we have one, else to stderr.
+ * Print to current monitor if we have one, else to stream.
* TODO should return int, so callers can calculate width, but that
* requires surgery to monitor_vprintf(). Left for another day.
*/
-void error_vprintf(const char *fmt, va_list ap)
+void monitor_vfprintf(FILE *stream, const char *fmt, va_list ap)
{
if (cur_mon && !monitor_cur_is_qmp()) {
monitor_vprintf(cur_mon, fmt, ap);
} else {
- vfprintf(stderr, fmt, ap);
+ vfprintf(stream, fmt, ap);
}
}
+/*
+ * Print to current monitor if we have one, else to stderr.
+ * TODO should return int, so callers can calculate width, but that
+ * requires surgery to monitor_vprintf(). Left for another day.
+ */
+void error_vprintf(const char *fmt, va_list ap)
+{
+ monitor_vfprintf(stderr, fmt, ap);
+}
+
void error_vprintf_unless_qmp(const char *fmt, va_list ap)
{
if (cur_mon && !monitor_cur_is_qmp()) {
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 61e0300991..802c18a74e 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -104,22 +104,31 @@ static bool qdev_class_has_alias(DeviceClass *dc)
return (qdev_class_get_alias(dc) != NULL);
}
+static void out_printf(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ monitor_vfprintf(stdout, fmt, ap);
+ va_end(ap);
+}
+
static void qdev_print_devinfo(DeviceClass *dc)
{
- error_printf("name \"%s\"", object_class_get_name(OBJECT_CLASS(dc)));
+ out_printf("name \"%s\"", object_class_get_name(OBJECT_CLASS(dc)));
if (dc->bus_type) {
- error_printf(", bus %s", dc->bus_type);
+ out_printf(", bus %s", dc->bus_type);
}
if (qdev_class_has_alias(dc)) {
- error_printf(", alias \"%s\"", qdev_class_get_alias(dc));
+ out_printf(", alias \"%s\"", qdev_class_get_alias(dc));
}
if (dc->desc) {
- error_printf(", desc \"%s\"", dc->desc);
+ out_printf(", desc \"%s\"", dc->desc);
}
if (!dc->user_creatable) {
- error_printf(", no-user");
+ out_printf(", no-user");
}
- error_printf("\n");
+ out_printf("\n");
}
static void qdev_print_devinfos(bool show_no_user)
@@ -155,8 +164,7 @@ static void qdev_print_devinfos(bool show_no_user)
continue;
}
if (!cat_printed) {
- error_printf("%s%s devices:\n", i ? "\n" : "",
- cat_name[i]);
+ out_printf("%s%s devices:\n", i ? "\n" : "", cat_name[i]);
cat_printed = true;
}
qdev_print_devinfo(dc);
@@ -278,13 +286,11 @@ int qdev_device_help(QemuOpts *opts)
}
for (prop = prop_list; prop; prop = prop->next) {
- error_printf("%s.%s=%s", driver,
- prop->value->name,
- prop->value->type);
+ out_printf("%s.%s=%s", driver, prop->value->name, prop->value->type);
if (prop->value->has_description) {
- error_printf(" (%s)\n", prop->value->description);
+ out_printf(" (%s)\n", prop->value->description);
} else {
- error_printf("\n");
+ out_printf("\n");
}
}