1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

qemu: Convert virExec usage to virCommand

v2:
    Have virCommand cleanup intermediate process for us

v3:
    Preserve original FD closing behavior

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2011-05-06 16:10:40 -04:00
parent 0068b58c71
commit 1ba75cf9aa
2 changed files with 13 additions and 15 deletions

View File

@ -3298,11 +3298,9 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
int ret = -1; int ret = -1;
virDomainEventPtr event; virDomainEventPtr event;
int intermediatefd = -1; int intermediatefd = -1;
pid_t intermediate_pid = -1; virCommandPtr cmd = NULL;
int childstat;
if (header->version == 2) { if (header->version == 2) {
const char *intermediate_argv[3] = { NULL, "-dc", NULL };
const char *prog = qemudSaveCompressionTypeToString(header->compressed); const char *prog = qemudSaveCompressionTypeToString(header->compressed);
if (prog == NULL) { if (prog == NULL) {
qemuReportError(VIR_ERR_OPERATION_FAILED, qemuReportError(VIR_ERR_OPERATION_FAILED,
@ -3312,14 +3310,17 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
} }
if (header->compressed != QEMUD_SAVE_FORMAT_RAW) { if (header->compressed != QEMUD_SAVE_FORMAT_RAW) {
intermediate_argv[0] = prog; cmd = virCommandNewArgList(prog, "-dc", NULL);
intermediatefd = *fd; intermediatefd = *fd;
*fd = -1; *fd = -1;
if (virExec(intermediate_argv, NULL, NULL,
&intermediate_pid, intermediatefd, fd, NULL, 0) < 0) { virCommandSetInputFD(cmd, intermediatefd);
virCommandSetOutputFD(cmd, fd);
if (virCommandRunAsync(cmd, NULL) < 0) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, qemuReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to start decompression binary %s"), _("Failed to start decompression binary %s"),
intermediate_argv[0]); prog);
*fd = intermediatefd; *fd = intermediatefd;
goto out; goto out;
} }
@ -3330,7 +3331,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
ret = qemuProcessStart(conn, driver, vm, "stdio", true, *fd, path, ret = qemuProcessStart(conn, driver, vm, "stdio", true, *fd, path,
VIR_VM_OP_RESTORE); VIR_VM_OP_RESTORE);
if (intermediate_pid != -1) { if (intermediatefd != -1) {
if (ret < 0) { if (ret < 0) {
/* if there was an error setting up qemu, the intermediate /* if there was an error setting up qemu, the intermediate
* process will wait forever to write to stdout, so we * process will wait forever to write to stdout, so we
@ -3338,14 +3339,10 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
*/ */
VIR_FORCE_CLOSE(intermediatefd); VIR_FORCE_CLOSE(intermediatefd);
VIR_FORCE_CLOSE(*fd); VIR_FORCE_CLOSE(*fd);
kill(intermediate_pid, SIGTERM);
} }
/* Wait for intermediate process to exit */ if (virCommandWait(cmd, NULL) < 0)
while (waitpid(intermediate_pid, &childstat, 0) == -1 && ret = -1;
errno == EINTR) {
/* empty */
}
} }
VIR_FORCE_CLOSE(intermediatefd); VIR_FORCE_CLOSE(intermediatefd);
@ -3385,6 +3382,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
ret = 0; ret = 0;
out: out:
virCommandFree(cmd);
if (virSecurityManagerRestoreSavedStateLabel(driver->securityManager, if (virSecurityManagerRestoreSavedStateLabel(driver->securityManager,
vm, path) < 0) vm, path) < 0)
VIR_WARN("failed to restore save state label on %s", path); VIR_WARN("failed to restore save state label on %s", path);

View File

@ -2378,7 +2378,7 @@ int qemuProcessStart(virConnectPtr conn,
* because the child no longer exists. * because the child no longer exists.
*/ */
/* The virExec process that launches the daemon failed. Pending on /* The virCommand process that launches the daemon failed. Pending on
* when it failed (we can't determine for sure), there may be * when it failed (we can't determine for sure), there may be
* extra info in the domain log (if the hook failed for example). * extra info in the domain log (if the hook failed for example).
* *