diff --git a/ChangeLog b/ChangeLog index c8a76b2b59..358cd0b001 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Feb 26 16:01:04 GMT 2009 Daniel P. Berrange + + * 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 * Makefile.am configure.in examples/hellolibvirt/Makefile.am diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fdda4789f3..c38e142d19 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -294,6 +294,7 @@ virEnumToString; virEventAddHandle; virEventRemoveHandle; virExec; +virExecWithHook; virSetCloseExec; virSetNonBlock; virFormatMacAddr; diff --git a/src/util.c b/src/util.c index 990433a275..16d905e1c3 100644 --- a/src/util.c +++ b/src/util.c @@ -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; } diff --git a/src/util.h b/src/util.h index a79cfa7c77..87cbf67477 100644 --- a/src/util.h +++ b/src/util.h @@ -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,