Take a look at kernel/kmod.c:call_usermodehelper(). Copy it.
This will make your thread a child of keventd. This takes
care of things like chrootedness, uids, cwds, signal masks,
reaping children, open files, and all the other crud which
you can accidentally inherit from your caller.
something like:
struct my_struct
{
struct tq_struct tq;
void (*function)(void *);
struct semaphore sem;
<other stuff>
};
/* keventd runs this */
void helper(void *data)
{
struct my_struct *my_ptr = data;
kernel_thread(my_ptr->function, my_ptr, CLONE_FLAGS|SIGCHLD);
}
start_thread(struct my_struct *my_ptr)
{
my_ptr->tq.sync = 0;
INIT_LIST_HEAD(&my_ptr->tq.list);
my_ptr->routine = helper;
my_ptr->data = my_ptr;
schedule_task(&my_ptr->tq);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/