Commit e87df986 authored by Al Viro's avatar Al Viro Committed by Richard Weinberger

um: simplify set_handler()

For one thing, we always block the same signals (IRQ ones - IO, WINCH, VTALRM),
so there's no need to pass sa_mask elements in arguments.  For another, the
flags depend only on whether it's an IRQ signal or not (we add SA_RESTART
for them).
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent d5c7e8b4
...@@ -225,7 +225,7 @@ extern char *get_umid(void); ...@@ -225,7 +225,7 @@ extern char *get_umid(void);
extern void timer_init(void); extern void timer_init(void);
extern void set_sigstack(void *sig_stack, int size); extern void set_sigstack(void *sig_stack, int size);
extern void remove_sigstack(void); extern void remove_sigstack(void);
extern void set_handler(int sig, void (*handler)(int), int flags, ...); extern void set_handler(int sig, void (*handler)(int));
extern int change_sig(int signal, int on); extern int change_sig(int signal, int on);
extern void block_signals(void); extern void block_signals(void);
extern void unblock_signals(void); extern void unblock_signals(void);
......
...@@ -235,20 +235,13 @@ int __init can_drop_memory(void) ...@@ -235,20 +235,13 @@ int __init can_drop_memory(void)
void init_new_thread_signals(void) void init_new_thread_signals(void)
{ {
set_handler(SIGSEGV, (__sighandler_t) sig_handler, SA_ONSTACK, set_handler(SIGSEGV, (__sighandler_t) sig_handler);
SIGIO, SIGWINCH, SIGVTALRM, -1); set_handler(SIGTRAP, (__sighandler_t) sig_handler);
set_handler(SIGTRAP, (__sighandler_t) sig_handler, SA_ONSTACK, set_handler(SIGFPE, (__sighandler_t) sig_handler);
SIGIO, SIGWINCH, SIGVTALRM, -1); set_handler(SIGILL, (__sighandler_t) sig_handler);
set_handler(SIGFPE, (__sighandler_t) sig_handler, SA_ONSTACK, set_handler(SIGBUS, (__sighandler_t) sig_handler);
SIGIO, SIGWINCH, SIGVTALRM, -1);
set_handler(SIGILL, (__sighandler_t) sig_handler, SA_ONSTACK,
SIGIO, SIGWINCH, SIGVTALRM, -1);
set_handler(SIGBUS, (__sighandler_t) sig_handler, SA_ONSTACK,
SIGIO, SIGWINCH, SIGVTALRM, -1);
signal(SIGHUP, SIG_IGN); signal(SIGHUP, SIG_IGN);
set_handler(SIGIO, (__sighandler_t) sig_handler);
set_handler(SIGIO, (__sighandler_t) sig_handler,
SA_ONSTACK | SA_RESTART, SIGIO, SIGWINCH, SIGVTALRM, -1);
signal(SIGWINCH, SIG_IGN); signal(SIGWINCH, SIG_IGN);
signal(SIGTERM, SIG_DFL); signal(SIGTERM, SIG_DFL);
} }
......
...@@ -111,8 +111,7 @@ void alarm_handler(int sig, struct sigcontext *sc) ...@@ -111,8 +111,7 @@ void alarm_handler(int sig, struct sigcontext *sc)
void timer_init(void) void timer_init(void)
{ {
set_handler(SIGVTALRM, (__sighandler_t) alarm_handler, set_handler(SIGVTALRM, (__sighandler_t) alarm_handler);
SA_ONSTACK | SA_RESTART, SIGIO, SIGWINCH, -1);
} }
void set_sigstack(void *sig_stack, int size) void set_sigstack(void *sig_stack, int size)
...@@ -174,27 +173,28 @@ static void hard_handler(int sig, siginfo_t *info, void *p) ...@@ -174,27 +173,28 @@ static void hard_handler(int sig, siginfo_t *info, void *p)
handle_signal(sig, (struct sigcontext *) &uc->uc_mcontext); handle_signal(sig, (struct sigcontext *) &uc->uc_mcontext);
} }
void set_handler(int sig, void (*handler)(int), int flags, ...) void set_handler(int sig, void (*handler)(int))
{ {
struct sigaction action; struct sigaction action;
va_list ap; int flags = SA_SIGINFO | SA_ONSTACK;
sigset_t sig_mask; sigset_t sig_mask;
int mask;
handlers[sig] = (void (*)(int, struct sigcontext *)) handler; handlers[sig] = (void (*)(int, struct sigcontext *)) handler;
action.sa_sigaction = hard_handler; action.sa_sigaction = hard_handler;
/* block irq ones */
sigemptyset(&action.sa_mask); sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGVTALRM);
va_start(ap, flags); sigaddset(&action.sa_mask, SIGIO);
while ((mask = va_arg(ap, int)) != -1) sigaddset(&action.sa_mask, SIGWINCH);
sigaddset(&action.sa_mask, mask);
va_end(ap);
if (sig == SIGSEGV) if (sig == SIGSEGV)
flags |= SA_NODEFER; flags |= SA_NODEFER;
action.sa_flags = flags | SA_SIGINFO; if (sigismember(&action.sa_mask, sig))
flags |= SA_RESTART; /* if it's an irq signal */
action.sa_flags = flags;
action.sa_restorer = NULL; action.sa_restorer = NULL;
if (sigaction(sig, &action, NULL) < 0) if (sigaction(sig, &action, NULL) < 0)
panic("sigaction failed - errno = %d\n", errno); panic("sigaction failed - errno = %d\n", errno);
......
...@@ -659,8 +659,7 @@ int start_idle_thread(void *stack, jmp_buf *switch_buf) ...@@ -659,8 +659,7 @@ int start_idle_thread(void *stack, jmp_buf *switch_buf)
{ {
int n; int n;
set_handler(SIGWINCH, (__sighandler_t) sig_handler, set_handler(SIGWINCH, (__sighandler_t) sig_handler);
SA_ONSTACK | SA_RESTART, SIGIO, SIGVTALRM, -1);
/* /*
* Can't use UML_SETJMP or UML_LONGJMP here because they save * Can't use UML_SETJMP or UML_LONGJMP here because they save
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment