mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-14 08:35:15 +00:00
fdstream: separate out virCommandPtr cleanup
Let's us de-nest some of the logic, and will simplify upcoming patches
This commit is contained in:
parent
441e881e9a
commit
c0e870376c
@ -240,6 +240,46 @@ virFDStreamAddCallback(virStreamPtr st,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
virFDStreamCloseCommand(struct virFDStreamData *fdst)
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
ssize_t len;
|
||||||
|
int status;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!fdst->cmd)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ((len = saferead(fdst->errfd, buf, sizeof(buf)-1)) < 0)
|
||||||
|
buf[0] = '\0';
|
||||||
|
else
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
virCommandRawStatus(fdst->cmd);
|
||||||
|
if (virCommandWait(fdst->cmd, &status) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (status != 0) {
|
||||||
|
if (buf[0] != '\0') {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", buf);
|
||||||
|
} else if (WIFEXITED(status)) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("I/O helper exited with status %d"),
|
||||||
|
WEXITSTATUS(status));
|
||||||
|
} else {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("I/O helper exited abnormally"));
|
||||||
|
}
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
virCommandFree(fdst->cmd);
|
||||||
|
fdst->cmd = NULL;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virFDStreamCloseInt(virStreamPtr st, bool streamAbort)
|
virFDStreamCloseInt(virStreamPtr st, bool streamAbort)
|
||||||
@ -285,37 +325,8 @@ virFDStreamCloseInt(virStreamPtr st, bool streamAbort)
|
|||||||
|
|
||||||
/* mutex locked */
|
/* mutex locked */
|
||||||
ret = VIR_CLOSE(fdst->fd);
|
ret = VIR_CLOSE(fdst->fd);
|
||||||
if (fdst->cmd) {
|
if (virFDStreamCloseCommand(fdst) < 0)
|
||||||
char buf[1024];
|
ret = -1;
|
||||||
ssize_t len;
|
|
||||||
int status;
|
|
||||||
if ((len = saferead(fdst->errfd, buf, sizeof(buf)-1)) < 0)
|
|
||||||
buf[0] = '\0';
|
|
||||||
else
|
|
||||||
buf[len] = '\0';
|
|
||||||
|
|
||||||
virCommandRawStatus(fdst->cmd);
|
|
||||||
if (virCommandWait(fdst->cmd, &status) < 0) {
|
|
||||||
ret = -1;
|
|
||||||
} else if (status != 0) {
|
|
||||||
if (buf[0] == '\0') {
|
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("I/O helper exited with status %d"),
|
|
||||||
WEXITSTATUS(status));
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("I/O helper exited abnormally"));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
buf);
|
|
||||||
}
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
virCommandFree(fdst->cmd);
|
|
||||||
fdst->cmd = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_CLOSE(fdst->errfd) < 0)
|
if (VIR_CLOSE(fdst->errfd) < 0)
|
||||||
VIR_DEBUG("ignoring failed close on fd %d", fdst->errfd);
|
VIR_DEBUG("ignoring failed close on fd %d", fdst->errfd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user