--- sched.bak Mon Apr 30 16:14:16 2001 +++ sched.c Mon Apr 30 16:41:48 2001 @@ -86,6 +86,7 @@ unsigned long prof_shift = 0; extern void mem_use(void); +extern struct task_struct *child_reaper; unsigned long volatile jiffies=0; @@ -2058,31 +2059,55 @@ } /* - * Put all the gunge required to become a kernel thread without - * attached user resources in one place where it belongs. + * Put all the gunge required to become a kernel thread without + * attached user resources in one place where it belongs. + * + * Kernel 2.4.4-pre3, andrewm#uow.edu.au: reparent the caller + * to init and set the exit signal to SIGCHLD so the thread + * will be properly reaped if it exist. */ - + void daemonize(void) { struct fs_struct *fs; + struct task_struct *this_task = current; /* - * If we were started as result of loading a module, close all of the - * user space pages. We don't need them, and if we didn't close them - * they would be locked into memory. - */ - exit_mm(current); + * If we were started as result of loading a module, close all of the + * user space pages. We don't need them, and if we didn't close them + * they would be locked into memory. + */ + exit_mm(this_task); - current->session = 1; - current->pgrp = 1; + this_task->session = 1; + this_task->pgrp = 1; /* Become as one with the init task */ - exit_fs(current); /* current->fs->count--; */ + exit_fs(this_task); /* this_task->fs->count--; */ fs = init_task.fs; - current->fs = fs; + this_task->fs = fs; atomic_inc(&fs->count); + exit_files(this_task); /* this_task->files->count-- */ + this_task->files = init_task.files; + atomic_inc(&this_task->files->count); + + write_lock_irq(&tasklist_lock); + + /* Reparent to init */ + REMOVE_LINKS(this_task); + this_task->p_pptr = child_reaper; + this_task->p_opptr = child_reaper; + SET_LINKS(this_task); + + /* Set the exit signal to SIGCHLD so we signal init on exit */ + if (this_task->exit_signal != 0) { + printk(KERN_ERR "task `%s' exit_signal %d in daemonize()\n", + this_task->comm, this_task->exit_signal); + } + this_task->exit_signal = SIGCHLD; + write_unlock_irq(&tasklist_lock); } void __init init_idle(void)