Commit 3bfae933 authored by Dave McCracken's avatar Dave McCracken Committed by Christoph Hellwig

[PATCH] Thread group exit problem reappeared

A long time ago there was thread group code that at exit time tried to
reparent a task to another task in the thread group.  I discovered a major
race condition in this code, and submitted a patch that removed it.  This
patch was accepted in, I think, 2.4.12.  The code reappeared in 2.4.18 and
sometime in the 2.5 tree before 2.5.15, breaking applications that use
thread groups.

As part of chasing this down, I figured out a way to remove the race
condition while still preserving this behavior.  I've attached a patch
against 2.5.15 that fixes it.
parent fa82a1da
...@@ -231,7 +231,7 @@ void daemonize(void) ...@@ -231,7 +231,7 @@ void daemonize(void)
/* /*
* When we die, we re-parent all our children. * When we die, we re-parent all our children.
* Try to give them to another thread in our process * Try to give them to another thread in our thread
* group, and if no such member exists, give it to * group, and if no such member exists, give it to
* the global child reaper process (ie "init") * the global child reaper process (ie "init")
*/ */
...@@ -241,8 +241,14 @@ static inline void forget_original_parent(struct task_struct * father) ...@@ -241,8 +241,14 @@ static inline void forget_original_parent(struct task_struct * father)
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
/* Next in our thread group */ /* Next in our thread group, if they're not already exiting */
reaper = next_thread(father); reaper = father;
do {
reaper = next_thread(reaper);
if (!(reaper->flags & PF_EXITING))
break;
} while (reaper != father);
if (reaper == father) if (reaper == father)
reaper = child_reaper; reaper = child_reaper;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment