mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Add support for a exec callback in virExecWithHook
This commit is contained in:
parent
66780313c2
commit
2e187bcbca
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Thu Feb 26 17:13:09 CET 2009 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* Makefile.am configure.in examples/hellolibvirt/Makefile.am
|
* Makefile.am configure.in examples/hellolibvirt/Makefile.am
|
||||||
|
@ -294,6 +294,7 @@ virEnumToString;
|
|||||||
virEventAddHandle;
|
virEventAddHandle;
|
||||||
virEventRemoveHandle;
|
virEventRemoveHandle;
|
||||||
virExec;
|
virExec;
|
||||||
|
virExecWithHook;
|
||||||
virSetCloseExec;
|
virSetCloseExec;
|
||||||
virSetNonBlock;
|
virSetNonBlock;
|
||||||
virFormatMacAddr;
|
virFormatMacAddr;
|
||||||
|
43
src/util.c
43
src/util.c
@ -202,7 +202,10 @@ __virExec(virConnectPtr conn,
|
|||||||
const fd_set *keepfd,
|
const fd_set *keepfd,
|
||||||
pid_t *retpid,
|
pid_t *retpid,
|
||||||
int infd, int *outfd, int *errfd,
|
int infd, int *outfd, int *errfd,
|
||||||
int flags) {
|
int flags,
|
||||||
|
virExecHook hook,
|
||||||
|
void *data)
|
||||||
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int null, i, openmax;
|
int null, i, openmax;
|
||||||
int pipeout[2] = {-1,-1};
|
int pipeout[2] = {-1,-1};
|
||||||
@ -416,6 +419,9 @@ __virExec(virConnectPtr conn,
|
|||||||
childerr != childout)
|
childerr != childout)
|
||||||
close(childerr);
|
close(childerr);
|
||||||
|
|
||||||
|
if (hook)
|
||||||
|
(hook)(data);
|
||||||
|
|
||||||
if (envp)
|
if (envp)
|
||||||
execve(argv[0], (char **) argv, (char**)envp);
|
execve(argv[0], (char **) argv, (char**)envp);
|
||||||
else
|
else
|
||||||
@ -450,13 +456,16 @@ __virExec(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
virExec(virConnectPtr conn,
|
virExecWithHook(virConnectPtr conn,
|
||||||
const char *const*argv,
|
const char *const*argv,
|
||||||
const char *const*envp,
|
const char *const*envp,
|
||||||
const fd_set *keepfd,
|
const fd_set *keepfd,
|
||||||
pid_t *retpid,
|
pid_t *retpid,
|
||||||
int infd, int *outfd, int *errfd,
|
int infd, int *outfd, int *errfd,
|
||||||
int flags) {
|
int flags,
|
||||||
|
virExecHook hook,
|
||||||
|
void *data)
|
||||||
|
{
|
||||||
char *argv_str;
|
char *argv_str;
|
||||||
|
|
||||||
if ((argv_str = virArgvToString(argv)) == NULL) {
|
if ((argv_str = virArgvToString(argv)) == NULL) {
|
||||||
@ -467,7 +476,21 @@ virExec(virConnectPtr conn,
|
|||||||
VIR_FREE(argv_str);
|
VIR_FREE(argv_str);
|
||||||
|
|
||||||
return __virExec(conn, argv, envp, keepfd, retpid, infd, outfd, errfd,
|
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
|
static int
|
||||||
@ -585,7 +608,7 @@ virRun(virConnectPtr conn,
|
|||||||
|
|
||||||
if ((execret = __virExec(conn, argv, NULL, NULL,
|
if ((execret = __virExec(conn, argv, NULL, NULL,
|
||||||
&childpid, -1, &outfd, &errfd,
|
&childpid, -1, &outfd, &errfd,
|
||||||
VIR_EXEC_NONE)) < 0) {
|
VIR_EXEC_NONE, NULL, NULL)) < 0) {
|
||||||
ret = execret;
|
ret = execret;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
15
src/util.h
15
src/util.h
@ -41,6 +41,21 @@ enum {
|
|||||||
int virSetNonBlock(int fd);
|
int virSetNonBlock(int fd);
|
||||||
int virSetCloseExec(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,
|
int virExec(virConnectPtr conn,
|
||||||
const char *const*argv,
|
const char *const*argv,
|
||||||
const char *const*envp,
|
const char *const*envp,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user