signals: cleanup the usage of t/current in do_sigaction()
authorOleg Nesterov <oleg@redhat.com>
Fri, 6 Jun 2014 21:36:51 +0000 (14:36 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 6 Jun 2014 23:08:11 +0000 (16:08 -0700)
The usage of "task_struct *t" and "current" in do_sigaction() looks really
annoying and chaotic.  Initially "t" is used as a cached value of current
but not consistently, then it is reused as a loop variable and we have to
use "current" again.

Clean up this mess and also convert the code to use for_each_thread().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/signal.c

index c088011f873cdc7df3bd5f9f8184662405c59fbf..a6d8c3af0ad6296f0e9c21da3bd22921f342723f 100644 (file)
@@ -3068,16 +3068,16 @@ COMPAT_SYSCALL_DEFINE4(rt_tgsigqueueinfo,
 
 int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
 {
-       struct task_struct *t = current;
+       struct task_struct *p = current, *t;
        struct k_sigaction *k;
        sigset_t mask;
 
        if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig)))
                return -EINVAL;
 
-       k = &t->sighand->action[sig-1];
+       k = &p->sighand->action[sig-1];
 
-       spin_lock_irq(&current->sighand->siglock);
+       spin_lock_irq(&p->sighand->siglock);
        if (oact)
                *oact = *k;
 
@@ -3096,17 +3096,16 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
                 *   (for example, SIGCHLD), shall cause the pending signal to
                 *   be discarded, whether or not it is blocked"
                 */
-               if (sig_handler_ignored(sig_handler(t, sig), sig)) {
+               if (sig_handler_ignored(sig_handler(p, sig), sig)) {
                        sigemptyset(&mask);
                        sigaddset(&mask, sig);
-                       flush_sigqueue_mask(&mask, &t->signal->shared_pending);
-                       do {
+                       flush_sigqueue_mask(&mask, &p->signal->shared_pending);
+                       for_each_thread(p, t)
                                flush_sigqueue_mask(&mask, &t->pending);
-                       } while_each_thread(current, t);
                }
        }
 
-       spin_unlock_irq(&current->sighand->siglock);
+       spin_unlock_irq(&p->sighand->siglock);
        return 0;
 }