Factor qemudMonitorSend() out of qemudMonitorCommandExtra()

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
This commit is contained in:
Mark McLoughlin 2009-07-22 20:17:14 +01:00
parent be44cabd7f
commit 9de2972c30
1 changed files with 23 additions and 8 deletions

View File

@ -2213,6 +2213,27 @@ qemuMonitorDiscardPendingData(virDomainObjPtr vm) {
} while (ret > 0); } 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;
}
static int static int
qemudMonitorCommandExtra(const virDomainObjPtr vm, qemudMonitorCommandExtra(const virDomainObjPtr vm,
@ -2222,14 +2243,10 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm,
char **reply) { char **reply) {
int size = 0; int size = 0;
char *buf = NULL; char *buf = NULL;
size_t cmdlen = strlen(cmd);
size_t extralen = extra ? strlen(extra) : 0;
qemuMonitorDiscardPendingData(vm); qemuMonitorDiscardPendingData(vm);
if (safewrite(vm->monitor, cmd, cmdlen) != cmdlen) if (qemudMonitorSend(vm, cmd) < 0)
return -1;
if (safewrite(vm->monitor, "\r", 1) != 1)
return -1; return -1;
*reply = NULL; *reply = NULL;
@ -2264,9 +2281,7 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm,
if (buf) { if (buf) {
if (extra) { if (extra) {
if (strstr(buf, extraPrompt) != NULL) { if (strstr(buf, extraPrompt) != NULL) {
if (safewrite(vm->monitor, extra, extralen) != extralen) if (qemudMonitorSend(vm, extra) < 0)
return -1;
if (safewrite(vm->monitor, "\r", 1) != 1)
return -1; return -1;
extra = NULL; extra = NULL;
} }