Name: Daemonize idle task Author: Rusty Russell Status: Tested on 2.5.9 D: This patch allows daemonize() to be called on another process (if D: not started yet), and calls it on the idle task. diff -urpN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.28.27210/include/linux/sched.h linux-2.5.28.27210.updated/include/linux/sched.h --- linux-2.5.28.27210/include/linux/sched.h Thu Jul 25 10:13:18 2002 +++ linux-2.5.28.27210.updated/include/linux/sched.h Fri Jul 26 17:59:05 2002 @@ -645,7 +645,12 @@ extern void exit_files(struct task_struc extern void exit_sighand(struct task_struct *); extern void reparent_to_init(void); -extern void daemonize(void); +extern void __daemonize(struct task_struct *); +static inline void daemonize(void) +{ + __daemonize(current); +} + extern task_t *child_reaper; extern int do_execve(char *, char **, char **, struct pt_regs *); diff -urpN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.28.27210/kernel/exit.c linux-2.5.28.27210.updated/kernel/exit.c --- linux-2.5.28.27210/kernel/exit.c Thu Jul 25 10:13:18 2002 +++ linux-2.5.28.27210.updated/kernel/exit.c Fri Jul 26 17:59:05 2002 @@ -200,32 +200,30 @@ void reparent_to_init(void) * Put all the gunge required to become a kernel thread without * attached user resources in one place where it belongs. */ - -void daemonize(void) +void __daemonize(struct task_struct *tsk) { struct fs_struct *fs; - /* * 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); + exit_mm(tsk); - current->session = 1; - current->pgrp = 1; - current->tty = NULL; + tsk->session = 1; + tsk->pgrp = 1; + tsk->tty = NULL; /* Become as one with the init task */ - exit_fs(current); /* current->fs->count--; */ + exit_fs(tsk); /* current->fs->count--; */ fs = init_task.fs; - current->fs = fs; + tsk->fs = fs; atomic_inc(&fs->count); - exit_files(current); - current->files = init_task.files; - atomic_inc(¤t->files->count); + exit_files(tsk); + tsk->files = init_task.files; + atomic_inc(&tsk->files->count); } /* diff -urpN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.28.27210/kernel/sched.c linux-2.5.28.27210.updated/kernel/sched.c --- linux-2.5.28.27210/kernel/sched.c Thu Jul 25 10:13:18 2002 +++ linux-2.5.28.27210.updated/kernel/sched.c Fri Jul 26 18:00:13 2002 @@ -1717,6 +1717,9 @@ void __init init_idle(task_t *idle, int runqueue_t *idle_rq = cpu_rq(cpu), *rq = cpu_rq(task_cpu(idle)); unsigned long flags; + if (idle != &init_task) + __daemonize(idle); + local_irq_save(flags); double_rq_lock(idle_rq, rq);