On Wed, Jul 22, 2009 at 10:57:33PM +0100, Mark McLoughlin wrote: > Add a little helper function to write the monitor command followed by > carriage return in a single write. > > This doesn't make any real difference, but allows us to more easily > switch to using sendmsg() when using the monitor over a unix socket. > > * src/qemu_conf.c: split qemudMonitorSend() out > --- > src/qemu_driver.c | 31 +++++++++++++++++++++++-------- > 1 files changed, 23 insertions(+), 8 deletions(-) > > diff --git a/src/qemu_driver.c b/src/qemu_driver.c > index 4f0c60e..7d4de9e 100644 > --- a/src/qemu_driver.c > +++ b/src/qemu_driver.c > @@ -2012,6 +2012,27 @@ qemuMonitorDiscardPendingData(virDomainObjPtr vm) { > } while (ret > 0); > } > > +static int > +qemudMonitorSend(const virDomainObjPtr vm, > + const char *cmd) > +{ > + char *full; > + size_t len; > + int ret = -1; > + > + if (virAsprintf(&full, "%s\r", cmd) < 0) > + return -1; > + > + len = strlen(full); > + > + if (safewrite(vm->monitor, full, len) != len) > + goto out; > + > + ret = 0; > +out: > + VIR_FREE(full); > + return ret; > +} It would seem easier to just keep the original model of two safewrite() calls, than to introduce an extra allocation & free here. Not a mustfix for comitting, but it'd be nicer. > > static int > qemudMonitorCommandExtra(const virDomainObjPtr vm, > @@ -2021,14 +2042,10 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm, > char **reply) { > int size = 0; > char *buf = NULL; > - size_t cmdlen = strlen(cmd); > - size_t extralen = extra ? strlen(extra) : 0; > > qemuMonitorDiscardPendingData(vm); > > - if (safewrite(vm->monitor, cmd, cmdlen) != cmdlen) > - return -1; > - if (safewrite(vm->monitor, "\r", 1) != 1) > + if (qemudMonitorSend(vm, cmd) < 0) > return -1; > > *reply = NULL; > @@ -2063,9 +2080,7 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm, > if (buf) { > if (extra) { > if (strstr(buf, extraPrompt) != NULL) { > - if (safewrite(vm->monitor, extra, extralen) != extralen) > - return -1; > - if (safewrite(vm->monitor, "\r", 1) != 1) > + if (qemudMonitorSend(vm, extra) < 0) > return -1; > extra = NULL; > } ACK, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list