]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sigaction.c
52722b08ae124f7f343a9b7970ed902b84572b2b
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sigaction.c
1 /* Copyright (C) 1997-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #include <errno.h>
19 #include <signal.h>
20 #include <string.h>
21
22 #include <sysdep.h>
23 #include <sys/syscall.h>
24
25 /* New ports should not define the obsolete SA_RESTORER, however some
26 architecture requires for compat mode and/or due old ABI. */
27 #include <kernel_sigaction.h>
28
29 #ifndef SA_RESTORER
30 # define SET_SA_RESTORER(kact, act)
31 # define RESET_SA_RESTORER(act, kact)
32 #endif
33
34 /* SPARC passes the restore function as an argument to rt_sigaction. */
35 #ifndef STUB
36 # define STUB(act, sigsetsize) (sigsetsize)
37 #endif
38
39 /* If ACT is not NULL, change the action for SIG to *ACT.
40 If OACT is not NULL, put the old action for SIG in *OACT. */
41 int
42 __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
43 {
44 int result;
45
46 struct kernel_sigaction kact, koact;
47
48 if (act)
49 {
50 kact.k_sa_handler = act->sa_handler;
51 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
52 kact.sa_flags = act->sa_flags;
53 SET_SA_RESTORER (&kact, act);
54 }
55
56 /* XXX The size argument hopefully will have to be changed to the
57 real size of the user-level sigset_t. */
58 result = INLINE_SYSCALL_CALL (rt_sigaction, sig,
59 act ? &kact : NULL,
60 oact ? &koact : NULL, STUB (act, _NSIG / 8));
61
62 if (oact && result >= 0)
63 {
64 oact->sa_handler = koact.k_sa_handler;
65 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
66 oact->sa_flags = koact.sa_flags;
67 RESET_SA_RESTORER (oact, &koact);
68 }
69 return result;
70 }
71 libc_hidden_def (__libc_sigaction)
72
73 #include <nptl/sigaction.c>