[libvirt] [PATCH] Sanitize qemu monitor reads

Cole Robinson crobinso at redhat.com
Tue Sep 23 20:56:08 UTC 2008


Reading from the qemu monitor pulls in a whole bunch of
useless control characters. For example, sending the
command 'somecomm' to the monitor returns:

somecomm
unknown command: 'somecomm'
(qemu)

Which is 36 characters, however we end up reading over 200.
The amount we read actually grows quadratically as a function
of the command length. This prevents us from reporting monitor
output to the user (incase some command fails) and seriously
diminishes the value of the domain logfiles.

The attached patch tries to sanitize this a bit. After reading
all the output, we search for the first occurrence of the full
command string. If found, we search from there for the first
newline (which marks the beginning of the monitor response).
If these are found, we only return the command, and everything
after the newline. If only the command is found, we just drop
everything before it.

I've tested this on f9 and f8, there didn't seem to be any
problems. I think this should be pretty future proof as
well, so we hopefully won't be throwing out anything
valuable.

Thanks,
Cole

-------------- next part --------------
A non-text attachment was scrubbed...
Name: libvirt-qemu-monitor-sanitize.patch
Type: text/x-patch
Size: 2743 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20080923/18952bab/attachment-0001.bin>


More information about the libvir-list mailing list