提交 2e187bcb 编写于 作者: D Daniel P. Berrange

Add support for a exec callback in virExecWithHook

上级 66780313
Thu Feb 26 16:01:04 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
* src/libvirt_private.syms, src/util.c, src/util.h: Add new
virExecWithHook function to allow passing of a callback to run
between fork() & exec()
Thu Feb 26 17:13:09 CET 2009 Daniel Veillard <veillard@redhat.com>
* Makefile.am configure.in examples/hellolibvirt/Makefile.am
......
......@@ -294,6 +294,7 @@ virEnumToString;
virEventAddHandle;
virEventRemoveHandle;
virExec;
virExecWithHook;
virSetCloseExec;
virSetNonBlock;
virFormatMacAddr;
......
......@@ -202,7 +202,10 @@ __virExec(virConnectPtr conn,
const fd_set *keepfd,
pid_t *retpid,
int infd, int *outfd, int *errfd,
int flags) {
int flags,
virExecHook hook,
void *data)
{
pid_t pid;
int null, i, openmax;
int pipeout[2] = {-1,-1};
......@@ -416,6 +419,9 @@ __virExec(virConnectPtr conn,
childerr != childout)
close(childerr);
if (hook)
(hook)(data);
if (envp)
execve(argv[0], (char **) argv, (char**)envp);
else
......@@ -450,13 +456,16 @@ __virExec(virConnectPtr conn,
}
int
virExec(virConnectPtr conn,
const char *const*argv,
const char *const*envp,
const fd_set *keepfd,
pid_t *retpid,
int infd, int *outfd, int *errfd,
int flags) {
virExecWithHook(virConnectPtr conn,
const char *const*argv,
const char *const*envp,
const fd_set *keepfd,
pid_t *retpid,
int infd, int *outfd, int *errfd,
int flags,
virExecHook hook,
void *data)
{
char *argv_str;
if ((argv_str = virArgvToString(argv)) == NULL) {
......@@ -467,7 +476,21 @@ virExec(virConnectPtr conn,
VIR_FREE(argv_str);
return __virExec(conn, argv, envp, keepfd, retpid, infd, outfd, errfd,
flags);
flags, hook, data);
}
int
virExec(virConnectPtr conn,
const char *const*argv,
const char *const*envp,
const fd_set *keepfd,
pid_t *retpid,
int infd, int *outfd, int *errfd,
int flags)
{
return virExecWithHook(conn, argv, envp, keepfd, retpid,
infd, outfd, errfd,
flags, NULL, NULL);
}
static int
......@@ -585,7 +608,7 @@ virRun(virConnectPtr conn,
if ((execret = __virExec(conn, argv, NULL, NULL,
&childpid, -1, &outfd, &errfd,
VIR_EXEC_NONE)) < 0) {
VIR_EXEC_NONE, NULL, NULL)) < 0) {
ret = execret;
goto error;
}
......
......@@ -41,6 +41,21 @@ enum {
int virSetNonBlock(int fd);
int virSetCloseExec(int fd);
/* This will execute in the context of the first child
* after fork() but before execve() */
typedef int (*virExecHook)(void *data);
int virExecWithHook(virConnectPtr conn,
const char *const*argv,
const char *const*envp,
const fd_set *keepfd,
int *retpid,
int infd,
int *outfd,
int *errfd,
int flags,
virExecHook hook,
void *data);
int virExec(virConnectPtr conn,
const char *const*argv,
const char *const*envp,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册