]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: replace qemuMonitorEscapeShell by virBufferEscapeShell
authorGuido Günther <agx@sigxcpu.org>
Tue, 18 Oct 2011 19:09:13 +0000 (21:09 +0200)
committerGuido Günther <agx@sigxcpu.org>
Wed, 19 Oct 2011 07:24:01 +0000 (09:24 +0200)
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h

index c9dd69e061bf48d43a63951b0fba2b88735d3d4c..182e63dc514b968584faf84138e47438137873b3 100644 (file)
@@ -139,48 +139,6 @@ char *qemuMonitorEscapeArg(const char *in)
     return out;
 }
 
-char *qemuMonitorEscapeShell(const char *in)
-{
-    int len = 2; /* leading and trailing single quote */
-    int i, j;
-    char *out;
-
-    for (i = 0; in[i] != '\0'; i++) {
-        switch(in[i]) {
-        case '\'':
-            len += 4; /* '\'' */
-            break;
-        default:
-            len += 1;
-            break;
-        }
-    }
-
-    if (VIR_ALLOC_N(out, len + 1) < 0)
-        return NULL;
-
-    j = 0;
-    out[j++] = '\'';
-    for (i = 0; in[i] != '\0'; i++) {
-        switch(in[i]) {
-        case '\'':
-            out[j++] = '\'';
-            out[j++] = '\\';
-            out[j++] = '\'';
-            out[j++] = '\'';
-            break;
-        default:
-            out[j++] = in[i];
-            break;
-        }
-    }
-    out[j++] = '\'';
-    out[j] = '\0';
-
-    return out;
-}
-
-
 #if DEBUG_RAW_IO
 # include <c-ctype.h>
 static char * qemuMonitorEscapeNonPrintable(const char *text)
@@ -1734,6 +1692,7 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
     char *dest = NULL;
     int ret = -1;
     char *safe_target = NULL;
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
     VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%x",
           mon, argv, target, offset, flags);
 
@@ -1757,11 +1716,13 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
     }
 
     /* Migrate to file */
-    safe_target = qemuMonitorEscapeShell(target);
-    if (!safe_target) {
+    virBufferEscapeShell(&buf, target);
+    if (virBufferError(&buf)) {
         virReportOOMError();
+        virBufferFreeAndReset(&buf);
         goto cleanup;
     }
+    safe_target = virBufferContentAndReset(&buf);
 
     /* Two dd processes, sharing the same stdout, are necessary to
      * allow starting at an alignment of 512, but without wasting
index 3ec78ad66d73779486b4f150e55aafede0118a15..90e7b4590188e9ed3ec4ae3cb07c91631e436b53 100644 (file)
@@ -127,7 +127,6 @@ struct _qemuMonitorCallbacks {
 
 
 char *qemuMonitorEscapeArg(const char *in);
-char *qemuMonitorEscapeShell(const char *in);
 
 qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
                                virDomainChrSourceDefPtr config,