introduce PF_KTHREAD flag
authorOleg Nesterov <oleg@tv-sign.ru>
Fri, 25 Jul 2008 08:47:37 +0000 (01:47 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 25 Jul 2008 17:53:39 +0000 (10:53 -0700)
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>
fs/exec.c
include/linux/init_task.h
include/linux/sched.h
kernel/exit.c

index af249af4ccab1f487b4f600ee0a82b2ef2681e97..cd2e8c9b12494f6df3f25663f6dbdd6ec19ca8a5 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1326,6 +1326,7 @@ int do_execve(char * filename,
        if (retval < 0)
                goto out;
 
+       current->flags &= ~PF_KTHREAD;
        retval = search_binary_handler(bprm,regs);
        if (retval >= 0) {
                /* execve success */
index 93c45acf249ab20cc19d43c94021a25691be9c76..021d8e720c7941f17cd6a541a63b7a9275f68c9c 100644 (file)
@@ -122,7 +122,7 @@ extern struct group_info init_groups;
        .state          = 0,                                            \
        .stack          = &init_thread_info,                            \
        .usage          = ATOMIC_INIT(2),                               \
-       .flags          = 0,                                            \
+       .flags          = PF_KTHREAD,                                   \
        .lock_depth     = -1,                                           \
        .prio           = MAX_PRIO-20,                                  \
        .static_prio    = MAX_PRIO-20,                                  \
index 79e749dbf81e151dc1e40d79ab8268bc9d813d2f..eec64a4adb9d9f5ca56158736c4c4af843ce7f28 100644 (file)
@@ -1483,6 +1483,7 @@ static inline void put_task_struct(struct task_struct *t)
 #define PF_EXITING     0x00000004      /* getting shut down */
 #define PF_EXITPIDONE  0x00000008      /* pi exit done on shut down */
 #define PF_VCPU                0x00000010      /* I'm a virtual CPU */
+#define PF_KTHREAD     0x00000020      /* I am a kernel thread */
 #define PF_FORKNOEXEC  0x00000040      /* forked but didn't exec */
 #define PF_SUPERPRIV   0x00000100      /* used super-user privileges */
 #define PF_DUMPCORE    0x00000200      /* dumped core */
index a7799d8a640495756f63c579f48f048e568addae..28a44a2612dcdd6df6ab1d5746438230cae6492e 100644 (file)
@@ -430,7 +430,7 @@ void daemonize(const char *name, ...)
         * We don't want to have TIF_FREEZE set if the system-wide hibernation
         * or suspend transition begins right now.
         */
-       current->flags |= PF_NOFREEZE;
+       current->flags |= (PF_NOFREEZE | PF_KTHREAD);
 
        if (current->nsproxy != &init_nsproxy) {
                get_nsproxy(&init_nsproxy);