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 * as soon as they're available, so putting the signal on the shared queue 937 * will be equivalent to sending it to one such thread. 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 - 945 946 static void 947 __group_complete_signal(int sig, struct task_struct *p) 948 { 949 - unsigned int mask; 950 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 960 /* 961 * Now find a thread we can wake up to take the signal off the queue. ··· 960 * If the main thread wants the signal, it gets first crack. 961 * Probably the least surprising to the average bear. 962 */ 963 - if (wants_signal(sig, p, mask)) 964 t = p; 965 else if (thread_group_empty(p)) 966 /* ··· 978 t = p->signal->curr_target = p; 979 BUG_ON(t->tgid != p->tgid); 980 981 - while (!wants_signal(sig, t, mask)) { 982 t = next_thread(t); 983 if (t == p->signal->curr_target) 984 /*
··· 936 * as soon as they're available, so putting the signal on the shared queue 937 * will be equivalent to sending it to one such thread. 938 */ 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 + } 951 952 static void 953 __group_complete_signal(int sig, struct task_struct *p) 954 { 955 struct task_struct *t; 956 957 /* 958 * Now find a thread we can wake up to take the signal off the queue. ··· 963 * If the main thread wants the signal, it gets first crack. 964 * Probably the least surprising to the average bear. 965 */ 966 + if (wants_signal(sig, p)) 967 t = p; 968 else if (thread_group_empty(p)) 969 /* ··· 981 t = p->signal->curr_target = p; 982 BUG_ON(t->tgid != p->tgid); 983 984 + while (!wants_signal(sig, t)) { 985 t = next_thread(t); 986 if (t == p->signal->curr_target) 987 /*