[libvirt] [PATCH 4/7] Factor qemudMonitorSend() out of qemudMonitorCommandExtra()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
+}
 
 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;
                 }
-- 
1.6.2.5

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]