On Mon, 2005-01-17 at 13:11 +0100, Guillaume Thouvenin wrote: > +/* > + * fork_hook is a pointer to a function to call when forking if it > + * isn't NULL. > + */ > +void (*fork_hook) (int, int) = NULL; I added a lock to protect the global pointer "fork_hook". spinlock_t fork_hook_lock = SPIN_LOCK_UNLOCKED; I removed the identifier fork_hook_id and here is the new code for the fork_hook: /** * trace_fork: call a given external function when forking * @func: function to call * * This function sets the fork_hook and makes some sanity checks. * Function returns 0 on success, -1 on failure (ie hook is * already used). * Limitation: currently, it can be used by only one module */ int trace_fork(void (*func) (int, int)) { int err = 0; spin_lock(&fork_hook_lock); /* We can set the hook if it's not already used */ if (func != NULL) { if (fork_hook == NULL) fork_hook = func; else err = -EBUSY; } else /* no check when releasing */ fork_hook = NULL; spin_unlock(&fork_hook_lock); /* Request can not be satisfied */ return err; } EXPORT_SYMBOL(trace_fork); It implies a very small modification in relay_fork.c > --------8< relay_fork.c module ---------------------- > /** > * rfd_init - > */ > static int __init rfd_init(void) > { > int retval; > > retval = trace_fork(&rfd_relay_fork_info, TRACE_FORK_ID); retval = trace_fork(&rfd_relay_fork_info); ... > } > > /** > * rfd_cleanup - > */ > static void __exit rfd_cleanup(void) > { > struct list_head *pos; /* use as a loop counter */ > struct list_head *next; /* temporary storage */ > trace_fork(NULL, TRACE_FORK_ID); /* don't forget to release the fork hook */ trace_fork(NULL); ... > } Any comments are welcome Guillaume -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/