+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
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};
childerr != childout)
close(childerr);
+ if (hook)
+ (hook)(data);
+
if (envp)
execve(argv[0], (char **) argv, (char**)envp);
else
}
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) {
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
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;
}
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,