linux: Consolidate sigaction implementation
[glibc.git] / sysdeps / unix / sysv / linux / sigaction.c
blob0e6851a148a3b931f3f733ce2c1fa304c1c66f7e
1 /* Copyright (C) 1997-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
18 #include <errno.h>
19 #include <signal.h>
20 #include <string.h>
22 #include <sysdep.h>
23 #include <sys/syscall.h>
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>
29 #ifndef SA_RESTORER
30 # define SET_SA_RESTORER(kact, act)
31 # define RESET_SA_RESTORER(act, kact)
32 #endif
34 /* SPARC passes the restore function as an argument to rt_sigaction. */
35 #ifndef STUB
36 # define STUB(act)
37 #endif
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)
44 int result;
46 struct kernel_sigaction kact, koact;
48 if (act)
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);
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);
62 if (oact && result >= 0)
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);
69 return result;
71 libc_hidden_def (__libc_sigaction)
73 #include <nptl/sigaction.c>