2010/12/7 Eric Blake <eblake@xxxxxxxxxx>: > * src/util/sysinfo.c (virSysinfoRead): Use virCommand instead of > virExec. > --- > v2: remove unused variable, rebase on top of whitespace cleanups. > > This patch is awaiting review on these prerequisites: > https://www.redhat.com/archives/libvir-list/2010-December/msg00318.html > https://www.redhat.com/archives/libvir-list/2010-December/msg00321.html > > Â Â path = virFindFileInPath(SYSINFO_SMBIOS_DECODER); > Â Â if (path == NULL) { > @@ -108,43 +106,13 @@ virSysinfoRead(void) { > Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂSYSINFO_SMBIOS_DECODER); > Â Â Â Â return NULL; > Â Â } > - Â Âargv[0] = path; > > - Â Âres = virExec(argv, NULL, NULL, &pid, -1, &outfd, &errfd, > - Â Â Â Â Â Â Â Â ÂVIR_EXEC_NONE | VIR_EXEC_NONBLOCK); > - Â Âif (res < 0) { > + Â Âcmd = virCommandNewArgList(path, "-q", "-t", "0,1", NULL); > + Â ÂvirCommandSetOutputBuffer(cmd, &outbuf); > + Â Âif (virCommandRun(cmd, NULL) < 0) { > Â Â Â Â virSmbiosReportError(VIR_ERR_INTERNAL_ERROR, > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â_("Failed to execute command %s"), > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âpath); > - Â Â Â Âres = 1; > - Â Â Â Âgoto cleanup; > - Â Â} > - > - Â Â/* > - Â Â * we are interested in the output, capture it and errors too > - Â Â */ > - Â Âif (virPipeReadUntilEOF(outfd, errfd, &outbuf, &errbuf) < 0) { > - Â Â Â ÂvirReportSystemError(errno, _("cannot wait for '%s'"), path); > - Â Â Â Âwhile (waitpid(pid, &exitstatus, 0) == -1 && errno == EINTR) > - Â Â Â Â Â Â; > - Â Â Â Âgoto cleanup; > - Â Â} > - > - Â Âif (outbuf) > - Â Â Â ÂVIR_DEBUG("Command stdout: %s", outbuf); > - Â Âif (errbuf) > - Â Â Â ÂVIR_DEBUG("Command stderr: %s", errbuf); > - > - Â Âwhile ((waitret = waitpid(pid, &exitstatus, 0) == -1) && > - Â Â Â Â Â (errno == EINTR)); > - Â Âif (waitret == -1) { > - Â Â Â ÂvirReportSystemError(errno, _("Failed to wait for '%s'"), path); > - Â Â Â Âgoto cleanup; > - Â Â} > - Â Âif (exitstatus != 0) { > - Â Â Â ÂvirSmbiosReportError(VIR_ERR_INTERNAL_ERROR, > - Â Â Â Â Â Â Â Â Â Â Â Â Â Â _("command %s failed with error code %d:%s"), > - Â Â Â Â Â Â Â Â Â Â Â Â Â Â path, exitstatus, errbuf); > Â Â Â Â goto cleanup; > Â Â } > > @@ -227,8 +195,7 @@ virSysinfoRead(void) { > > Âcleanup: > Â Â VIR_FREE(outbuf); > - Â ÂVIR_FREE(errbuf); > - Â ÂVIR_FREE(path); > + Â ÂvirCommandFree(cmd); Why not free path anymore, doesn't it leak now? ACK, with that possible leak addressed. Matthias -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list