Browse Source

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>
tags/v3.1.0-rc0
Marc-André Lureau 10 months ago
parent
commit
a95db58f21
3 changed files with 35 additions and 16 deletions
  1. 3
    0
      include/monitor/monitor.h
  2. 13
    3
      monitor.c
  3. 19
    13
      qdev-monitor.c

+ 3
- 0
include/monitor/monitor.h View File

@@ -47,4 +47,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
47 47
 void monitor_fdset_dup_fd_remove(int dup_fd);
48 48
 int monitor_fdset_dup_fd_find(int dup_fd);
49 49
 
50
+void monitor_vfprintf(FILE *stream,
51
+                      const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
52
+
50 53
 #endif /* MONITOR_H */

+ 13
- 3
monitor.c View File

@@ -4493,19 +4493,29 @@ static void monitor_readline_flush(void *opaque)
4493 4493
 }
4494 4494
 
4495 4495
 /*
4496
- * Print to current monitor if we have one, else to stderr.
4496
+ * Print to current monitor if we have one, else to stream.
4497 4497
  * TODO should return int, so callers can calculate width, but that
4498 4498
  * requires surgery to monitor_vprintf().  Left for another day.
4499 4499
  */
4500
-void error_vprintf(const char *fmt, va_list ap)
4500
+void monitor_vfprintf(FILE *stream, const char *fmt, va_list ap)
4501 4501
 {
4502 4502
     if (cur_mon && !monitor_cur_is_qmp()) {
4503 4503
         monitor_vprintf(cur_mon, fmt, ap);
4504 4504
     } else {
4505
-        vfprintf(stderr, fmt, ap);
4505
+        vfprintf(stream, fmt, ap);
4506 4506
     }
4507 4507
 }
4508 4508
 
4509
+/*
4510
+ * Print to current monitor if we have one, else to stderr.
4511
+ * TODO should return int, so callers can calculate width, but that
4512
+ * requires surgery to monitor_vprintf().  Left for another day.
4513
+ */
4514
+void error_vprintf(const char *fmt, va_list ap)
4515
+{
4516
+    monitor_vfprintf(stderr, fmt, ap);
4517
+}
4518
+
4509 4519
 void error_vprintf_unless_qmp(const char *fmt, va_list ap)
4510 4520
 {
4511 4521
     if (cur_mon && !monitor_cur_is_qmp()) {

+ 19
- 13
qdev-monitor.c View File

@@ -104,22 +104,31 @@ static bool qdev_class_has_alias(DeviceClass *dc)
104 104
     return (qdev_class_get_alias(dc) != NULL);
105 105
 }
106 106
 
107
+static void out_printf(const char *fmt, ...)
108
+{
109
+    va_list ap;
110
+
111
+    va_start(ap, fmt);
112
+    monitor_vfprintf(stdout, fmt, ap);
113
+    va_end(ap);
114
+}
115
+
107 116
 static void qdev_print_devinfo(DeviceClass *dc)
108 117
 {
109
-    error_printf("name \"%s\"", object_class_get_name(OBJECT_CLASS(dc)));
118
+    out_printf("name \"%s\"", object_class_get_name(OBJECT_CLASS(dc)));
110 119
     if (dc->bus_type) {
111
-        error_printf(", bus %s", dc->bus_type);
120
+        out_printf(", bus %s", dc->bus_type);
112 121
     }
113 122
     if (qdev_class_has_alias(dc)) {
114
-        error_printf(", alias \"%s\"", qdev_class_get_alias(dc));
123
+        out_printf(", alias \"%s\"", qdev_class_get_alias(dc));
115 124
     }
116 125
     if (dc->desc) {
117
-        error_printf(", desc \"%s\"", dc->desc);
126
+        out_printf(", desc \"%s\"", dc->desc);
118 127
     }
119 128
     if (!dc->user_creatable) {
120
-        error_printf(", no-user");
129
+        out_printf(", no-user");
121 130
     }
122
-    error_printf("\n");
131
+    out_printf("\n");
123 132
 }
124 133
 
125 134
 static void qdev_print_devinfos(bool show_no_user)
@@ -155,8 +164,7 @@ static void qdev_print_devinfos(bool show_no_user)
155 164
                 continue;
156 165
             }
157 166
             if (!cat_printed) {
158
-                error_printf("%s%s devices:\n", i ? "\n" : "",
159
-                             cat_name[i]);
167
+                out_printf("%s%s devices:\n", i ? "\n" : "", cat_name[i]);
160 168
                 cat_printed = true;
161 169
             }
162 170
             qdev_print_devinfo(dc);
@@ -278,13 +286,11 @@ int qdev_device_help(QemuOpts *opts)
278 286
     }
279 287
 
280 288
     for (prop = prop_list; prop; prop = prop->next) {
281
-        error_printf("%s.%s=%s", driver,
282
-                     prop->value->name,
283
-                     prop->value->type);
289
+        out_printf("%s.%s=%s", driver, prop->value->name, prop->value->type);
284 290
         if (prop->value->has_description) {
285
-            error_printf(" (%s)\n", prop->value->description);
291
+            out_printf(" (%s)\n", prop->value->description);
286 292
         } else {
287
-            error_printf("\n");
293
+            out_printf("\n");
288 294
         }
289 295
     }
290 296
 

Loading…
Cancel
Save