diff options
author | Oleg Nesterov <oleg@tv-sign.ru> | 2008-07-25 04:47:37 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-25 13:53:39 -0400 |
commit | 7b34e4283c685f5cc6ba6d30e939906eee0d4bcf (patch) | |
tree | 6822edd5c63db79e97b8c5379a18a058bc5405ff | |
parent | 3d749b9e676b26584a47e75c235aa6f69d0697ae (diff) |
introduce PF_KTHREAD flag
Introduce the new PF_KTHREAD flag to mark the kernel threads. It is set
by INIT_TASK() and copied to the forked childs (we could set it in
kthreadd() along with PF_NOFREEZE instead).
daemonize() was changed as well. In that case testing of PF_KTHREAD is
racy, but daemonize() is hopeless anyway.
This flag is cleared in do_execve(), before search_binary_handler().
Probably not the best place, we can do this in exec_mmap() or in
start_thread(), or clear it along with PF_FORKNOEXEC. But I think this
doesn't matter in practice, and if do_execve() fails kthread should die
soon.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/exec.c | 1 | ||||
-rw-r--r-- | include/linux/init_task.h | 2 | ||||
-rw-r--r-- | include/linux/sched.h | 1 | ||||
-rw-r--r-- | kernel/exit.c | 2 |
4 files changed, 4 insertions, 2 deletions
@@ -1326,6 +1326,7 @@ int do_execve(char * filename, | |||
1326 | if (retval < 0) | 1326 | if (retval < 0) |
1327 | goto out; | 1327 | goto out; |
1328 | 1328 | ||
1329 | current->flags &= ~PF_KTHREAD; | ||
1329 | retval = search_binary_handler(bprm,regs); | 1330 | retval = search_binary_handler(bprm,regs); |
1330 | if (retval >= 0) { | 1331 | if (retval >= 0) { |
1331 | /* execve success */ | 1332 | /* execve success */ |
diff --git a/include/linux/init_task.h b/include/linux/init_task.h index 93c45acf249a..021d8e720c79 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h | |||
@@ -122,7 +122,7 @@ extern struct group_info init_groups; | |||
122 | .state = 0, \ | 122 | .state = 0, \ |
123 | .stack = &init_thread_info, \ | 123 | .stack = &init_thread_info, \ |
124 | .usage = ATOMIC_INIT(2), \ | 124 | .usage = ATOMIC_INIT(2), \ |
125 | .flags = 0, \ | 125 | .flags = PF_KTHREAD, \ |
126 | .lock_depth = -1, \ | 126 | .lock_depth = -1, \ |
127 | .prio = MAX_PRIO-20, \ | 127 | .prio = MAX_PRIO-20, \ |
128 | .static_prio = MAX_PRIO-20, \ | 128 | .static_prio = MAX_PRIO-20, \ |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 79e749dbf81e..eec64a4adb9d 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1483,6 +1483,7 @@ static inline void put_task_struct(struct task_struct *t) | |||
1483 | #define PF_EXITING 0x00000004 /* getting shut down */ | 1483 | #define PF_EXITING 0x00000004 /* getting shut down */ |
1484 | #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ | 1484 | #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ |
1485 | #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ | 1485 | #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ |
1486 | #define PF_KTHREAD 0x00000020 /* I am a kernel thread */ | ||
1486 | #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ | 1487 | #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ |
1487 | #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ | 1488 | #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ |
1488 | #define PF_DUMPCORE 0x00000200 /* dumped core */ | 1489 | #define PF_DUMPCORE 0x00000200 /* dumped core */ |
diff --git a/kernel/exit.c b/kernel/exit.c index a7799d8a6404..28a44a2612dc 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -430,7 +430,7 @@ void daemonize(const char *name, ...) | |||
430 | * We don't want to have TIF_FREEZE set if the system-wide hibernation | 430 | * We don't want to have TIF_FREEZE set if the system-wide hibernation |
431 | * or suspend transition begins right now. | 431 | * or suspend transition begins right now. |
432 | */ | 432 | */ |
433 | current->flags |= PF_NOFREEZE; | 433 | current->flags |= (PF_NOFREEZE | PF_KTHREAD); |
434 | 434 | ||
435 | if (current->nsproxy != &init_nsproxy) { | 435 | if (current->nsproxy != &init_nsproxy) { |
436 | get_nsproxy(&init_nsproxy); | 436 | get_nsproxy(&init_nsproxy); |