exit: reparent: introduce find_alive_thread()
Add the new simple helper to factor out the for_each_thread() code in find_child_reaper() and find_new_reaper(). It can also simplify the potential PF_EXITING -> exit_state change, plus perhaps we can change this code to take SIGNAL_GROUP_EXIT into account. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Aaron Tomlin <atomlin@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Kay Sievers <kay@vrfy.org> Cc: Lennart Poettering <lennart@poettering.net> Cc: Sterling Alexander <stalexan@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
					parent
					
						
							
								1109909c7d
							
						
					
				
			
			
				commit
				
					
						c9dc05bfdb
					
				
			
		
					 1 changed files with 19 additions and 13 deletions
				
			
		| 
						 | 
					@ -459,6 +459,17 @@ static void exit_mm(struct task_struct *tsk)
 | 
				
			||||||
	clear_thread_flag(TIF_MEMDIE);
 | 
						clear_thread_flag(TIF_MEMDIE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct task_struct *find_alive_thread(struct task_struct *p)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct task_struct *t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for_each_thread(p, t) {
 | 
				
			||||||
 | 
							if (!(t->flags & PF_EXITING))
 | 
				
			||||||
 | 
								return t;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct task_struct *find_child_reaper(struct task_struct *father)
 | 
					static struct task_struct *find_child_reaper(struct task_struct *father)
 | 
				
			||||||
	__releases(&tasklist_lock)
 | 
						__releases(&tasklist_lock)
 | 
				
			||||||
	__acquires(&tasklist_lock)
 | 
						__acquires(&tasklist_lock)
 | 
				
			||||||
| 
						 | 
					@ -469,9 +480,8 @@ static struct task_struct *find_child_reaper(struct task_struct *father)
 | 
				
			||||||
	if (likely(reaper != father))
 | 
						if (likely(reaper != father))
 | 
				
			||||||
		return reaper;
 | 
							return reaper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for_each_thread(father, reaper) {
 | 
						reaper = find_alive_thread(father);
 | 
				
			||||||
		if (reaper->flags & PF_EXITING)
 | 
						if (reaper) {
 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
		pid_ns->child_reaper = reaper;
 | 
							pid_ns->child_reaper = reaper;
 | 
				
			||||||
		return reaper;
 | 
							return reaper;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -497,16 +507,13 @@ static struct task_struct *find_child_reaper(struct task_struct *father)
 | 
				
			||||||
static struct task_struct *find_new_reaper(struct task_struct *father,
 | 
					static struct task_struct *find_new_reaper(struct task_struct *father,
 | 
				
			||||||
					   struct task_struct *child_reaper)
 | 
										   struct task_struct *child_reaper)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct task_struct *thread;
 | 
						struct task_struct *thread, *reaper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for_each_thread(father, thread) {
 | 
						thread = find_alive_thread(father);
 | 
				
			||||||
		if (thread->flags & PF_EXITING)
 | 
						if (thread)
 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
		return thread;
 | 
							return thread;
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (father->signal->has_child_subreaper) {
 | 
						if (father->signal->has_child_subreaper) {
 | 
				
			||||||
		struct task_struct *reaper;
 | 
					 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Find the first ->is_child_subreaper ancestor in our pid_ns.
 | 
							 * Find the first ->is_child_subreaper ancestor in our pid_ns.
 | 
				
			||||||
		 * We start from father to ensure we can not look into another
 | 
							 * We start from father to ensure we can not look into another
 | 
				
			||||||
| 
						 | 
					@ -520,12 +527,11 @@ static struct task_struct *find_new_reaper(struct task_struct *father,
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			if (!reaper->signal->is_child_subreaper)
 | 
								if (!reaper->signal->is_child_subreaper)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			for_each_thread(reaper, thread) {
 | 
								thread = find_alive_thread(reaper);
 | 
				
			||||||
				if (!(thread->flags & PF_EXITING))
 | 
								if (thread)
 | 
				
			||||||
				return thread;
 | 
									return thread;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return child_reaper;
 | 
						return child_reaper;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue