[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/15] QMP: Disable monitor print functions
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 10/15] QMP: Disable monitor print functions |
Date: |
Thu, 19 Nov 2009 13:13:38 -0200 |
We still have handlers which will call monitor print functions
in several places.
If they do this when we are in control mode, we will be emitting
garbage to our clients.
To avoid this situation, 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 printed.
Signed-off-by: Luiz Capitulino <address@hidden>
---
monitor.c | 14 +++++++++++---
1 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/monitor.c b/monitor.c
index dc4583f..e85f990 100644
--- a/monitor.c
+++ b/monitor.c
@@ -97,6 +97,7 @@ typedef struct MonitorControl {
uint8_t buf[1024];
int size;
QObject *id;
+ int print_enabled;
} MonitorControl;
struct Monitor {
@@ -184,9 +185,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, "monitor print");
+ } else {
+ char buf[4096];
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ monitor_puts(mon, buf);
+ }
}
void monitor_printf(Monitor *mon, const char *fmt, ...)
@@ -270,7 +275,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);
}
--
1.6.5.3.148.g785c5
- [Qemu-devel] [PATCH 01/15] monitor: Introduce MONITOR_USE_CONTROL flag, (continued)
- [Qemu-devel] [PATCH 01/15] monitor: Introduce MONITOR_USE_CONTROL flag, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 02/15] monitor: Command-line flag to enable control mode, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 03/15] monitor: Move handler calling code to its own function, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 04/15] QError: Add errors used by QMP, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 05/15] QMP: chardev handling, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 06/15] QMP: Output support, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 07/15] QMP: Input support, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 08/15] QMP: Asynchronous events infrastructure, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 09/15] QMP: Introduce basic asynchronous events, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 10/15] QMP: Disable monitor print functions,
Luiz Capitulino <=
- [Qemu-devel] [PATCH 11/15] QMP: Introduce README file, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 12/15] QMP: Introduce specification, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 13/15] QMP: Introduce qmp-events.txt, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 14/15] QMP: Introduce qmp-shell, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 15/15] QMP: Introduce vm-info, Luiz Capitulino, 2009/11/19
- [Qemu-devel] Re: [RFC v0 00/15] QEMU Monitor Protocol, Avi Kivity, 2009/11/19