[libvirt] [PATCH] Make QEMU text monitor parsing more robust
Daniel Veillard
veillard at redhat.com
Wed Dec 9 09:46:58 UTC 2009
On Tue, Dec 08, 2009 at 06:08:04PM +0000, Daniel P. Berrange wrote:
> The QEMU 0.10.0 release (and possibly other 0.10.x) has a bug where
> it sometimes/often forgets to display the initial monitor greeting
> line, soley printing a (qemu). This in turn confuses the text
> console parsing because it has a '(qemu)' it is not expecting. The
> confusion results in a negative malloc. Bad things follow.
>
> This re-writes the text console handling to be more robust. The key
> idea is that it should only look for a (qemu), once it has seen the
> original command echo'd back. This ensures it'll skip the bogus stray
> (qemu) with broken QEMUs.
>
> * src/qemu/qemu_monitor.c: Add some (disabled) debug code
> * src/qemu/qemu_monitor_text.c: Re-write way command replies
> are detected
> ---
> src/qemu/qemu_monitor.c | 28 +++++++++++
> src/qemu/qemu_monitor_text.c | 102 +++++++++++++++++++++++++++--------------
> 2 files changed, 95 insertions(+), 35 deletions(-)
>
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index abb763c..103cf28 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -39,6 +39,8 @@
>
> #define VIR_FROM_THIS VIR_FROM_QEMU
>
> +#define QEMU_DEBUG_RAW_IO 0
> +
> struct _qemuMonitor {
> virMutex lock;
> virCond notify;
> @@ -163,6 +165,24 @@ char *qemuMonitorEscapeShell(const char *in)
> }
>
>
> +#if QEMU_DEBUG_RAW_IO
> +#include <c-ctype.h>
> +static char * qemuMonitorEscapeNonPrintable(const char *text)
> +{
> + int i;
> + virBuffer buf = VIR_BUFFER_INITIALIZER;
> + for (i = 0 ; text[i] != '\0' ; i++) {
> + if (c_isprint(text[i]) ||
Hum I just hope c_isprint behaviour doesn't depend on the user locale,
otherwise I would just replace it with an explicit value test on the
ASCII range, not a big deal since it's just for debug though ...
> + text[i] == '\n' ||
> + (text[i] == '\r' && text[i+1] == '\n'))
> + virBufferVSprintf(&buf,"%c", text[i]);
> + else
> + virBufferVSprintf(&buf, "0x%02x", text[i]);
> + }
> + return virBufferContentAndReset(&buf);
> +}
> +#endif
ACK,
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel at veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
More information about the libvir-list
mailing list