Make sure SIGKILL gets proper respect

Bhavesh P. Davda <bhavesh@avaya.com> noticed that SIGKILL wouldn't
properly kill a process under just the right cicumstances: a stopped
task that already had another signal queued would get the SIGKILL
queued onto the shared queue, and there it would remain until SIGCONT.

This simplifies the signal acceptance logic, and fixes the bug in the
process.

Losely based on an earlier patch by Bhavesh.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>

+14 -17
+14 -17
kernel/signal.c
··· 936 936 * as soon as they're available, so putting the signal on the shared queue 937 937 * will be equivalent to sending it to one such thread. 938 938 */ 939 - #define wants_signal(sig, p, mask) \ 940 - (!sigismember(&(p)->blocked, sig) \ 941 - && !((p)->state & mask) \ 942 - && !((p)->flags & PF_EXITING) \ 943 - && (task_curr(p) || !signal_pending(p))) 944 - 939 + static inline int wants_signal(int sig, struct task_struct *p) 940 + { 941 + if (sigismember(&p->blocked, sig)) 942 + return 0; 943 + if (p->flags & PF_EXITING) 944 + return 0; 945 + if (sig == SIGKILL) 946 + return 1; 947 + if (p->state & (TASK_STOPPED | TASK_TRACED)) 948 + return 0; 949 + return task_curr(p) || !signal_pending(p); 950 + } 945 951 946 952 static void 947 953 __group_complete_signal(int sig, struct task_struct *p) 948 954 { 949 - unsigned int mask; 950 955 struct task_struct *t; 951 - 952 - /* 953 - * Don't bother traced and stopped tasks (but 954 - * SIGKILL will punch through that). 955 - */ 956 - mask = TASK_STOPPED | TASK_TRACED; 957 - if (sig == SIGKILL) 958 - mask = 0; 959 956 960 957 /* 961 958 * Now find a thread we can wake up to take the signal off the queue. ··· 960 963 * If the main thread wants the signal, it gets first crack. 961 964 * Probably the least surprising to the average bear. 962 965 */ 963 - if (wants_signal(sig, p, mask)) 966 + if (wants_signal(sig, p)) 964 967 t = p; 965 968 else if (thread_group_empty(p)) 966 969 /* ··· 978 981 t = p->signal->curr_target = p; 979 982 BUG_ON(t->tgid != p->tgid); 980 983 981 - while (!wants_signal(sig, t, mask)) { 984 + while (!wants_signal(sig, t)) { 982 985 t = next_thread(t); 983 986 if (t == p->signal->curr_target) 984 987 /*