Re: [libvirt] Some problem with the save function

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

 



Chris Lalancette wrote:
No, you are right.  This was part of the refactoring, and I just didn't re-read
the code.  I would prefer to move prog to the top of the block myself, and add
args there; it just seems tidier.

I agree that it's tidier -- but looking at things in context, I'm not very comfortable putting the declarations at the very top of the function. Part of the reason is that everything else there is initialized, even if only to NULL; I hate to break such a convention, but at the same time, I find it dangerous to suppress any warnings the compiler might otherwise be able to generate should a codepath allow a variable be used uninitialized.

Does the below (creating a new code block and declaring both variables there) work for everyone?
>From c106334d8b41926ce5b6ef0917277091f3e1378e Mon Sep 17 00:00:00 2001
From: Charles Duffy <Charles_Duffy@xxxxxxxx>
Date: Thu, 17 Sep 2009 18:24:15 -0500
Subject: [PATCH] prevent attempt to call cat -c during virDomainSave to raw

---
 src/qemu_driver.c |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index a65334f..0f98a6c 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -3905,17 +3905,25 @@ static int qemudDomainSave(virDomainPtr dom,
         goto cleanup;
     }
 
-    const char *prog = qemudSaveCompressionTypeToString(header.compressed);
-    if (prog == NULL) {
-        qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
-                         _("Invalid compress format %d"), header.compressed);
-        goto cleanup;
-    }
+    {
+        const char *prog = qemudSaveCompressionTypeToString(header.compressed);
+        const char *args;
 
-    if (STREQ (prog, "raw"))
-        prog = "cat";
-    internalret = virAsprintf(&command, "migrate \"exec:"
-                              "%s -c >> '%s' 2>/dev/null\"", prog, safe_path);
+        if (prog == NULL) {
+            qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
+                             _("Invalid compress format %d"), header.compressed);
+            goto cleanup;
+        }
+
+        if (STREQ (prog, "raw")) {
+            prog = "cat";
+            args = "";
+        } else {
+            args = "-c";
+        }
+        internalret = virAsprintf(&command, "migrate \"exec:"
+                                  "%s %s >> '%s' 2>/dev/null\"", prog, args, safe_path);
+    }
 
     if (internalret < 0) {
         virReportOOMError(dom->conn);
-- 
1.6.4

--
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]