]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Convert qemu-img -help parsing to virCommand
authorCole Robinson <crobinso@redhat.com>
Fri, 6 May 2011 19:25:52 +0000 (15:25 -0400)
committerCole Robinson <crobinso@redhat.com>
Fri, 13 May 2011 18:19:08 +0000 (14:19 -0400)
src/storage/storage_backend.c

index 97a7e4b8e7a1152f320d532bd03387756a231f46..e05679da423256362fe6c900447dac562745f9f9 100644 (file)
@@ -602,28 +602,19 @@ enum {
 
 static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
 {
-    const char *const qemuarg[] = { qemuimg, "-h", NULL };
-    const char *const qemuenv[] = { "LC_ALL=C", NULL };
-    pid_t child = 0;
-    int status;
-    int newstdout = -1;
     char *help = NULL;
-    enum { MAX_HELP_OUTPUT_SIZE = 1024*8 };
     char *start;
     char *end;
     char *tmp;
     int ret = -1;
+    virCommandPtr cmd = virCommandNewArgList(qemuimg, "-h", NULL);
 
-    if (virExec(qemuarg, qemuenv, NULL,
-                &child, -1, &newstdout, NULL, VIR_EXEC_CLEAR_CAPS) < 0)
-        goto cleanup;
+    virCommandAddEnvString(cmd, "LC_ALL=C");
+    virCommandSetOutputBuffer(cmd, &help);
+    virCommandClearCaps(cmd);
 
-    if (virFileReadLimFD(newstdout, MAX_HELP_OUTPUT_SIZE, &help) < 0) {
-        virReportSystemError(errno,
-                             _("Unable to read '%s -h' output"),
-                             qemuimg);
+    if (virCommandRun(cmd, NULL) < 0)
         goto cleanup;
-    }
 
     start = strstr(help, " create ");
     end = strstr(start, "\n");
@@ -636,18 +627,8 @@ static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
         ret = QEMU_IMG_BACKING_FORMAT_NONE;
 
 cleanup:
+    virCommandFree(cmd);
     VIR_FREE(help);
-    VIR_FORCE_CLOSE(newstdout);
-    if (child) {
-        while (waitpid(child, &status, 0) == -1 && errno == EINTR);
-        if (status) {
-            tmp = virCommandTranslateStatus(status);
-            VIR_WARN("Unexpected status, qemu probably failed: %s",
-                     NULLSTR(tmp));
-            VIR_FREE(tmp);
-        }
-    }
-
     return ret;
 }