QMP: Disable monitor print functions
authorLuiz Capitulino <lcapitulino@redhat.com>
Fri, 27 Nov 2009 00:59:05 +0000 (22:59 -0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Thu, 3 Dec 2009 15:41:24 +0000 (09:41 -0600)
We still have handlers which will call monitor print functions
in several places. Usually to report errors.

If they do this when we are in control mode, we will be emitting
garbage to our clients.

To avoid this problem, this commit adds a way to disable those
functions. If any of them is called when in control mode, we will
emit a generic error.

Although this is far from the perfect solution, it guarantees
that only JSON is sent to Clients.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
monitor.c

index cd2f19c19acd74804d3bee12758139472e5132dd..af6d3d5d22c905655ef3b18a986afe1b10ca425b 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -98,6 +98,7 @@ struct mon_fd_t {
 
 typedef struct MonitorControl {
     QObject *id;
+    int print_enabled;
     JSONMessageParser parser;
 } MonitorControl;
 
@@ -186,9 +187,13 @@ static void monitor_puts(Monitor *mon, const char *str)
 
 void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
-    char buf[4096];
-    vsnprintf(buf, sizeof(buf), fmt, ap);
-    monitor_puts(mon, buf);
+    if (mon->mc && !mon->mc->print_enabled) {
+        qemu_error_new(QERR_UNDEFINED_ERROR);
+    } else {
+        char buf[4096];
+        vsnprintf(buf, sizeof(buf), fmt, ap);
+        monitor_puts(mon, buf);
+    }
 }
 
 void monitor_printf(Monitor *mon, const char *fmt, ...)
@@ -272,7 +277,10 @@ static void monitor_json_emitter(Monitor *mon, const QObject *data)
     json = qobject_to_json(data);
     assert(json != NULL);
 
+    mon->mc->print_enabled = 1;
     monitor_printf(mon, "%s\n", qstring_get_str(json));
+    mon->mc->print_enabled = 0;
+
     QDECREF(json);
 }