]> Pileus Git - ~andy/linux/blobdiff - kernel/exit.c
do_wait: fix waiting for the group stop with the dead leader
[~andy/linux] / kernel / exit.c
index efd30ccf38584f48c6ef68da62b9236479b6da69..0c06b9efae3b320e2ce8284ce1790d2eaf3c00b7 100644 (file)
@@ -980,12 +980,9 @@ static void check_stack_usage(void)
 {
        static DEFINE_SPINLOCK(low_water_lock);
        static int lowest_to_date = THREAD_SIZE;
-       unsigned long *n = end_of_stack(current);
        unsigned long free;
 
-       while (*n == 0)
-               n++;
-       free = (unsigned long)n - (unsigned long)end_of_stack(current);
+       free = stack_not_used(current);
 
        if (free >= lowest_to_date)
                return;
@@ -1420,6 +1417,18 @@ static int wait_task_zombie(struct task_struct *p, int options,
        return retval;
 }
 
+static int *task_stopped_code(struct task_struct *p, bool ptrace)
+{
+       if (ptrace) {
+               if (task_is_stopped_or_traced(p))
+                       return &p->exit_code;
+       } else {
+               if (p->signal->flags & SIGNAL_STOP_STOPPED)
+                       return &p->signal->group_exit_code;
+       }
+       return NULL;
+}
+
 /*
  * Handle sys_wait4 work for one task in state TASK_STOPPED.  We hold
  * read_lock(&tasklist_lock) on entry.  If we return zero, we still hold
@@ -1430,7 +1439,7 @@ static int wait_task_stopped(int ptrace, struct task_struct *p,
                             int options, struct siginfo __user *infop,
                             int __user *stat_addr, struct rusage __user *ru)
 {
-       int retval, exit_code, why;
+       int retval, exit_code, *p_code, why;
        uid_t uid = 0; /* unneeded, required by compiler */
        pid_t pid;
 
@@ -1440,22 +1449,16 @@ static int wait_task_stopped(int ptrace, struct task_struct *p,
        exit_code = 0;
        spin_lock_irq(&p->sighand->siglock);
 
-       if (unlikely(!task_is_stopped_or_traced(p)))
-               goto unlock_sig;
-
-       if (!ptrace && p->signal->group_stop_count > 0)
-               /*
-                * A group stop is in progress and this is the group leader.
-                * We won't report until all threads have stopped.
-                */
+       p_code = task_stopped_code(p, ptrace);
+       if (unlikely(!p_code))
                goto unlock_sig;
 
-       exit_code = p->exit_code;
+       exit_code = *p_code;
        if (!exit_code)
                goto unlock_sig;
 
        if (!unlikely(options & WNOWAIT))
-               p->exit_code = 0;
+               *p_code = 0;
 
        /* don't need the RCU readlock here as we're holding a spinlock */
        uid = __task_cred(p)->uid;
@@ -1611,7 +1614,7 @@ static int wait_consider_task(struct task_struct *parent, int ptrace,
         */
        *notask_error = 0;
 
-       if (task_is_stopped_or_traced(p))
+       if (task_stopped_code(p, ptrace))
                return wait_task_stopped(ptrace, p, options,
                                         infop, stat_addr, ru);