On Tue, May 10, 2011 at 04:07:52PM -0400, Cole Robinson wrote:
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
src/util/util.c | 68 ++++++------------------------------------------------
1 files changed, 8 insertions(+), 60 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c
index 2f2fbc8..f83b2d0 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -769,69 +769,17 @@ virExecWithHook(const char *const*argv,
int
virRun(const char *const*argv, int *status)
{
- pid_t childpid;
- int exitstatus, execret, waitret;
- int ret = -1;
- int errfd = -1, outfd = -1;
- char *outbuf = NULL;
- char *errbuf = NULL;
-
- if ((execret = virExecWithHook(argv, NULL, NULL,
- &childpid, -1, &outfd, &errfd,
- VIR_EXEC_NONE, NULL, NULL, NULL)) < 0) {
- ret = execret;
- goto error;
- }
-
- if (virPipeReadUntilEOF(outfd, errfd, &outbuf, &errbuf) < 0) {
- while (waitpid(childpid, &exitstatus, 0) == -1 && errno == EINTR)
- ;
- goto error;
- }
-
- if (outbuf)
- VIR_DEBUG("Command stdout: %s", outbuf);
- if (errbuf)
- VIR_DEBUG("Command stderr: %s", errbuf);
-
- while ((waitret = waitpid(childpid, &exitstatus, 0) == -1) &&
- errno == EINTR);
- if (waitret == -1) {
- virReportSystemError(errno,
- _("cannot wait for '%s'"),
- argv[0]);
- goto error;
- }
-
- if (status == NULL) {
- errno = EINVAL;
- if (exitstatus) {
- char *str = virCommandTranslateStatus(exitstatus);
- char *argv_str = virArgvToString(argv);
- if (!argv_str) {
- virReportOOMError();
- goto error;
- }
-
- virUtilError(VIR_ERR_INTERNAL_ERROR,
- _("'%s' exited unexpectedly: %s"),
- argv_str, NULLSTR(str));
+ virCommandPtr cmd = virCommandNew(argv[0]);
+ const char * const *tmp;
+ int ret;
- VIR_FREE(str);
- VIR_FREE(argv_str);
- goto error;
- }
- } else {
- *status = exitstatus;
+ tmp = argv;
+ while (*(++tmp)) {
+ virCommandAddArg(cmd, *tmp);
}
- ret = 0;
-
- error:
- VIR_FREE(outbuf);
- VIR_FREE(errbuf);
- VIR_FORCE_CLOSE(outfd);
- VIR_FORCE_CLOSE(errfd);
+ ret = virCommandRun(cmd, status);
+ virCommandFree(cmd);
return ret;
}
ACK
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|