clean up sloppy nested inclusion from pthread_impl.h
[musl] / src / signal / sigaction.c
1 #include <stdlib.h>
2 #include <signal.h>
3 #include <errno.h>
4 #include <string.h>
5 #include "syscall.h"
6 #include "pthread_impl.h"
7 #include "libc.h"
8 #include "ksigaction.h"
9
10 void __restore(), __restore_rt();
11
12 static pthread_t dummy(void) { return 0; }
13 weak_alias(dummy, __pthread_self_def);
14
15 int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
16 {
17         struct k_sigaction ksa;
18         if (sa) {
19                 if ((uintptr_t)sa->sa_handler > 1UL)
20                         __pthread_self_def();
21                 ksa.handler = sa->sa_handler;
22                 ksa.flags = sa->sa_flags | SA_RESTORER;
23                 ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore;
24                 memcpy(&ksa.mask, &sa->sa_mask, sizeof ksa.mask);
25         }
26         if (syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa:0, sizeof ksa.mask))
27                 return -1;
28         if (old) {
29                 old->sa_handler = ksa.handler;
30                 old->sa_flags = ksa.flags;
31                 memcpy(&old->sa_mask, &ksa.mask, sizeof ksa.mask);
32         }
33         return 0;
34 }
35
36 int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
37 {
38         if (sig-32U < 3) {
39                 errno = EINVAL;
40                 return -1;
41         }
42         return __libc_sigaction(sig, sa, old);
43 }
44
45 weak_alias(__sigaction, sigaction);