提交 b3ecd780 编写于 作者: C Cole Robinson

storage: Convert qemu-img -help parsing to virCommand

上级 aaf20355
...@@ -602,28 +602,19 @@ enum { ...@@ -602,28 +602,19 @@ enum {
static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg) 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; char *help = NULL;
enum { MAX_HELP_OUTPUT_SIZE = 1024*8 };
char *start; char *start;
char *end; char *end;
char *tmp; char *tmp;
int ret = -1; int ret = -1;
virCommandPtr cmd = virCommandNewArgList(qemuimg, "-h", NULL);
if (virExec(qemuarg, qemuenv, NULL, virCommandAddEnvString(cmd, "LC_ALL=C");
&child, -1, &newstdout, NULL, VIR_EXEC_CLEAR_CAPS) < 0) virCommandSetOutputBuffer(cmd, &help);
goto cleanup; virCommandClearCaps(cmd);
if (virFileReadLimFD(newstdout, MAX_HELP_OUTPUT_SIZE, &help) < 0) { if (virCommandRun(cmd, NULL) < 0)
virReportSystemError(errno,
_("Unable to read '%s -h' output"),
qemuimg);
goto cleanup; goto cleanup;
}
start = strstr(help, " create "); start = strstr(help, " create ");
end = strstr(start, "\n"); end = strstr(start, "\n");
...@@ -636,18 +627,8 @@ static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg) ...@@ -636,18 +627,8 @@ static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
ret = QEMU_IMG_BACKING_FORMAT_NONE; ret = QEMU_IMG_BACKING_FORMAT_NONE;
cleanup: cleanup:
virCommandFree(cmd);
VIR_FREE(help); 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; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册