diff --git a/kernel/signal.c b/kernel/signal.c index 52f881d..064f81f 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -944,7 +944,7 @@ static inline int wants_signal(int sig, struct task_struct *p) static void complete_signal(int sig, struct task_struct *p, int group) { struct signal_struct *signal = p->signal; - struct task_struct *t; + struct task_struct *t = p; /* * Now find a thread we can wake up to take the signal off the queue. @@ -952,33 +952,26 @@ static void complete_signal(int sig, struct task_struct *p, int group) * If the main thread wants the signal, it gets first crack. * Probably the least surprising to the average bear. */ - if (wants_signal(sig, p)) - t = p; - else if (!group || thread_group_empty(p)) - /* - * There is just one thread and it does not need to be woken. - * It will dequeue unblocked signals before it runs again. - */ - return; - else { - /* - * Otherwise try to find a suitable thread. - */ - t = signal->curr_target; - while (!wants_signal(sig, t)) { - t = next_thread(t); - if (t == signal->curr_target) - /* - * No thread needs to be woken. - * Any eligible threads will see - * the signal in the queue soon. - */ - return; + if (!group || thread_group_empty(p)) { + if (wants_signal(sig, t)) + goto found; + } else { + while_each_thread(p, t) { + if (wants_signal(sig, t)) + goto found; } - signal->curr_target = t; } /* + * No thread needs to be woken. + * Any eligible threads will see + * the signal in the queue soon. + */ + return; +found: + signal->curr_target = t; + + /* * Found a killable thread. If the signal will be fatal, * then start taking the whole group down immediately. */