]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Factor qemudMonitorSend() out of qemudMonitorCommandExtra()
authorMark McLoughlin <markmc@redhat.com>
Wed, 22 Jul 2009 19:17:14 +0000 (20:17 +0100)
committerMark McLoughlin <markmc@redhat.com>
Mon, 27 Jul 2009 14:31:51 +0000 (15:31 +0100)
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

index e4a5e18ab1d3edf2db07dda75468b835f9cea860..2b0e9c1cba1b6d35af1ec883c29b4a466f4a029d 100644 (file)
@@ -2213,6 +2213,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;
+}
 
 static int
 qemudMonitorCommandExtra(const virDomainObjPtr vm,
@@ -2222,14 +2243,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;
@@ -2264,9 +2281,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;
                 }