mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Add virRun() helper function (Dan Berrange)
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
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>
|
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
|
* src/xen_internal.c: Ensure cpumap is at least 8 bytes long
|
||||||
|
|||||||
38
src/util.c
38
src/util.c
@@ -33,6 +33,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef HAVE_PATHS_H
|
#ifdef HAVE_PATHS_H
|
||||||
@@ -203,6 +204,43 @@ virExecNonBlock(virConnectPtr conn,
|
|||||||
return(_virExec(conn, argv, retpid, infd, outfd, errfd, 1));
|
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__ */
|
#else /* __MINGW32__ */
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
int virExec(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
|
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 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);
|
int saferead(int fd, void *buf, size_t count);
|
||||||
ssize_t safewrite(int fd, const void *buf, size_t count);
|
ssize_t safewrite(int fd, const void *buf, size_t count);
|
||||||
|
|||||||
Reference in New Issue
Block a user