Browse Source

ptrace: introduce ptrace_reparented() helper

Add another trivial helper for the sake of grep.  It also auto-documents the
fact that ->parent != real_parent implies ->ptrace.

No functional changes.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Acked-by: Roland McGrath <roland@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Oleg Nesterov 17 years ago
parent
commit
53b6f9fbd3
2 changed files with 8 additions and 5 deletions
  1. 4 0
      include/linux/ptrace.h
  2. 4 5
      kernel/exit.c

+ 4 - 0
include/linux/ptrace.h

@@ -98,6 +98,10 @@ extern void ptrace_untrace(struct task_struct *child);
 extern int ptrace_may_attach(struct task_struct *task);
 extern int ptrace_may_attach(struct task_struct *task);
 extern int __ptrace_may_attach(struct task_struct *task);
 extern int __ptrace_may_attach(struct task_struct *task);
 
 
+static inline int ptrace_reparented(struct task_struct *child)
+{
+	return child->real_parent != child->parent;
+}
 static inline void ptrace_link(struct task_struct *child,
 static inline void ptrace_link(struct task_struct *child,
 			       struct task_struct *new_parent)
 			       struct task_struct *new_parent)
 {
 {

+ 4 - 5
kernel/exit.c

@@ -698,7 +698,7 @@ reparent_thread(struct task_struct *p, struct task_struct *father, int traced)
 	if (unlikely(traced)) {
 	if (unlikely(traced)) {
 		/* Preserve ptrace links if someone else is tracing this child.  */
 		/* Preserve ptrace links if someone else is tracing this child.  */
 		list_del_init(&p->ptrace_list);
 		list_del_init(&p->ptrace_list);
-		if (p->parent != p->real_parent)
+		if (ptrace_reparented(p))
 			list_add(&p->ptrace_list, &p->real_parent->ptrace_children);
 			list_add(&p->ptrace_list, &p->real_parent->ptrace_children);
 	} else {
 	} else {
 		/* If this child is being traced, then we're the one tracing it
 		/* If this child is being traced, then we're the one tracing it
@@ -865,8 +865,8 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
 	 * only has special meaning to our real parent.
 	 * only has special meaning to our real parent.
 	 */
 	 */
 	if (!task_detached(tsk) && thread_group_empty(tsk)) {
 	if (!task_detached(tsk) && thread_group_empty(tsk)) {
-		int signal = (tsk->parent == tsk->real_parent)
-				? tsk->exit_signal : SIGCHLD;
+		int signal = ptrace_reparented(tsk) ?
+				SIGCHLD : tsk->exit_signal;
 		do_notify_parent(tsk, signal);
 		do_notify_parent(tsk, signal);
 	} else if (tsk->ptrace) {
 	} else if (tsk->ptrace) {
 		do_notify_parent(tsk, SIGCHLD);
 		do_notify_parent(tsk, SIGCHLD);
@@ -1269,8 +1269,7 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
 		return 0;
 		return 0;
 	}
 	}
 
 
-	/* traced means p->ptrace, but not vice versa */
-	traced = (p->real_parent != p->parent);
+	traced = ptrace_reparented(p);
 
 
 	if (likely(!traced)) {
 	if (likely(!traced)) {
 		struct signal_struct *psig;
 		struct signal_struct *psig;