chiark / gitweb /
Merge gregkh@ehlo.org:/home/kay/public_html/pub/scm/linux/hotplug/udev-kay
[elogind.git] / klibc / klibc / sigaction.c
1 /*
2  * sigaction.c
3  */
4
5 #include <signal.h>
6 #include <sys/syscall.h>
7
8 __extern void __sigreturn(void);
9 __extern int __sigaction(int, const struct sigaction *, struct sigaction *);
10 __extern int __rt_sigaction(int, const struct sigaction *, struct sigaction *, size_t);
11
12 int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
13 {
14   int rv;
15
16 #if defined(__i386__) || defined(__x86_64__)
17   /* x86-64, and the Fedora i386 kernel, are broken without SA_RESTORER */
18   struct sigaction sa;
19
20   if ( act && !(act->sa_flags & SA_RESTORER) ) {
21     sa = *act;
22     act = &sa;
23
24     /* The kernel can't be trusted to have a valid default restorer */
25     sa.sa_flags |= SA_RESTORER;
26     sa.sa_restorer = &__sigreturn;
27   }
28 #endif
29
30 #ifdef __NR_sigaction
31   rv = __sigaction(sig, act, oact);
32 #else
33   rv = __rt_sigaction(sig, act, oact, sizeof(sigset_t));
34 #endif
35
36
37 #if defined(__i386__) || defined(__x86_64__)
38   if ( oact && (oact->sa_restorer == &__sigreturn) ) {
39     oact->sa_flags &= ~SA_RESTORER;
40   }
41 #endif
42
43   return rv;
44 }