
Daniel P. Berrange wrote:
On Mon, Dec 01, 2008 at 05:36:34PM -0500, Cole Robinson wrote:
The attached patch cleans up output we read from the qemu monitor. This is a simplified form of a patch I posted awhile ago. From the patch:
/* The monitor doesn't dump clean output after we have written to * it. Every character we write dumps a bunch of useless stuff, * so the result looks like "cXcoXcomXcommXcommaXcommanXcommand" * Try to throw away everything before the first full command * occurence, and inbetween the command and the newline starting * the response */
<snip>
This loooks a little overly complex to me, doesn't handle alloction failures in strdup correctly & leaks tmpbuf.
Argh, yeah, I'm always botching this.
if ((commptr = strstr(buf, cmd))) memmove(buf, commptr, strlen(commptr)+1);
Yes that's much simpler, though it doesn't take into account the control characters after the command string and before the newline starting the command response. We could just do: if ((commptr = strstr(buf, cmd))) memmove(buf, commptr, strlen(commptr)+1); if ((dupptr = strchr(buf, '\n')) memmove(buf+strlen(cmd), dupptr, strlen(dupptr)+1); I was also trying to avoid having the command string in the 'reply', but it was an unnecessary restriction. Updated patch attached. It also fixes an error check from the blockstats monitor command which wouldn't have worked in the first place, but should be accurate now. Thanks, Cole