From f9888b702241a0a644c6f7ae8baedd8a653c861b Mon Sep 17 00:00:00 2001 From: Oleg Nesterov Date: Fri, 6 Jun 2014 14:37:00 -0700 Subject: [PATCH] signals: introduce kernel_sigaction() Now that allow_signal() is really trivial we can unify it with disallow_signal(). Add the new helper, kernel_sigaction(), and reimplement allow_signal/disallow_signal as a trivial wrappers. This saves one EXPORT_SYMBOL() and the new helper can have more users. Signed-off-by: Oleg Nesterov Cc: Peter Zijlstra Cc: Al Viro Cc: David Woodhouse Cc: Frederic Weisbecker Cc: Geert Uytterhoeven Cc: Ingo Molnar Cc: Mathieu Desnoyers Cc: Richard Weinberger Cc: Steven Rostedt Cc: Tejun Heo Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/signal.h | 18 ++++++++++++++++-- kernel/signal.c | 40 ++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/include/linux/signal.h b/include/linux/signal.h index d6693629f85d..563c4e625c04 100644 --- a/include/linux/signal.h +++ b/include/linux/signal.h @@ -287,8 +287,22 @@ struct ksignal { extern int get_signal(struct ksignal *ksig); extern void signal_setup_done(int failed, struct ksignal *ksig, int stepping); extern void exit_signals(struct task_struct *tsk); -extern void allow_signal(int); -extern void disallow_signal(int); +extern void kernel_sigaction(int, __sighandler_t); + +static inline void allow_signal(int sig) +{ + /* + * Kernel threads handle their own signals. Let the signal code + * know it'll be handled, so that they don't get converted to + * SIGKILL or just silently dropped. + */ + kernel_sigaction(sig, (__force __sighandler_t)2); +} + +static inline void disallow_signal(int sig) +{ + kernel_sigaction(sig, SIG_IGN); +} extern struct kmem_cache *sighand_cachep; diff --git a/kernel/signal.c b/kernel/signal.c index 5b76a485bb02..8ff956985d61 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3125,37 +3125,25 @@ COMPAT_SYSCALL_DEFINE4(rt_tgsigqueueinfo, #endif /* - * Let kernel threads use this to say that they allow a certain signal. - * Must not be used if kthread was cloned with CLONE_SIGHAND. + * For kthreads only, must not be used if cloned with CLONE_SIGHAND */ -void allow_signal(int sig) +void kernel_sigaction(int sig, __sighandler_t action) { - /* - * Kernel threads handle their own signals. Let the signal code - * know it'll be handled, so that they don't get converted to - * SIGKILL or just silently dropped. - */ spin_lock_irq(¤t->sighand->siglock); - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2; + current->sighand->action[sig - 1].sa.sa_handler = action; + if (action == SIG_IGN) { + sigset_t mask; + + sigemptyset(&mask); + sigaddset(&mask, sig); + + flush_sigqueue_mask(&mask, ¤t->signal->shared_pending); + flush_sigqueue_mask(&mask, ¤t->pending); + recalc_sigpending(); + } spin_unlock_irq(¤t->sighand->siglock); } -EXPORT_SYMBOL(allow_signal); - -void disallow_signal(int sig) -{ - sigset_t mask; - - sigemptyset(&mask); - sigaddset(&mask, sig); - - spin_lock_irq(¤t->sighand->siglock); - current->sighand->action[(sig)-1].sa.sa_handler = SIG_IGN; - flush_sigqueue_mask(&mask, ¤t->signal->shared_pending); - flush_sigqueue_mask(&mask, ¤t->pending); - recalc_sigpending(); - spin_unlock_irq(¤t->sighand->siglock); -} -EXPORT_SYMBOL(disallow_signal); +EXPORT_SYMBOL(kernel_sigaction); int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) {