+Thu Jan 10 13:44:17 GMT 2008 Mark McLoughlin <markmc@redhat.com>
+
+ * src/util.[ch]: Add virRun() helper function (Dan Berrange)
+
Wed Jan 9 16:04:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/xen_internal.c: Ensure cpumap is at least 8 bytes long
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <string.h>
#ifdef HAVE_PATHS_H
return(_virExec(conn, argv, retpid, infd, outfd, errfd, 1));
}
+/**
+ * @conn connection to report errors against
+ * @argv NULL terminated argv to run
+ * @status optional variable to return exit status in
+ *
+ * Run a command without using the shell.
+ *
+ * If status is NULL, then return 0 if the command run and
+ * exited with 0 status; Otherwise return -1
+ *
+ * If status is not-NULL, then return 0 if the command ran.
+ * The status variable is filled with the command exit status
+ * and should be checked by caller for success. Return -1
+ * only if the command could not be run.
+ */
+int
+virRun(virConnectPtr conn,
+ char **argv,
+ int *status) {
+ int childpid, exitstatus, ret;
+
+ if ((ret = virExec(conn, argv, &childpid, -1, NULL, NULL)) < 0)
+ return ret;
+
+ while ((ret = waitpid(childpid, &exitstatus, 0) == -1) && errno == EINTR);
+ if (ret == -1)
+ return -1;
+
+ if (status == NULL) {
+ errno = EINVAL;
+ return (WIFEXITED(exitstatus) && WEXITSTATUS(exitstatus) == 0) ? 0 : -1;
+ } else {
+ *status = exitstatus;
+ return 0;
+ }
+}
+
#else /* __MINGW32__ */
int
int virExec(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
int virExecNonBlock(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
+int virRun(virConnectPtr conn, char **argv, int *status);
int saferead(int fd, void *buf, size_t count);
ssize_t safewrite(int fd, const void *buf, size_t count);