Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / sigaction.c
blob043d16486c8ebe80c55366bccf293adc58918f35
1 /* Copyright (C) 1997-2014 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 #include <kernel-features.h>
27 /* The difference here is that the sigaction structure used in the
28 kernel is not the same as we use in the libc. Therefore we must
29 translate it here. */
30 #include <kernel_sigaction.h>
33 /* If ACT is not NULL, change the action for SIG to *ACT.
34 If OACT is not NULL, put the old action for SIG in *OACT. */
35 int
36 __libc_sigaction (sig, act, oact)
37 int sig;
38 const struct sigaction *act;
39 struct sigaction *oact;
41 int result;
43 struct kernel_sigaction kact, koact;
45 if (act)
47 kact.k_sa_handler = act->sa_handler;
48 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
49 kact.sa_flags = act->sa_flags;
50 #ifdef HAVE_SA_RESTORER
51 kact.sa_restorer = act->sa_restorer;
52 #endif
55 /* XXX The size argument hopefully will have to be changed to the
56 real size of the user-level sigset_t. */
57 result = INLINE_SYSCALL (rt_sigaction, 4, sig,
58 act ? &kact : NULL,
59 oact ? &koact : NULL, _NSIG / 8);
61 if (oact && result >= 0)
63 oact->sa_handler = koact.k_sa_handler;
64 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
65 oact->sa_flags = koact.sa_flags;
66 #ifdef HAVE_SA_RESTORER
67 oact->sa_restorer = koact.sa_restorer;
68 #endif
70 return result;
72 libc_hidden_def (__libc_sigaction)
74 #ifdef WRAPPER_INCLUDE
75 # include WRAPPER_INCLUDE
76 #endif
78 #ifndef LIBC_SIGACTION
79 weak_alias (__libc_sigaction, __sigaction)
80 libc_hidden_weak (__sigaction)
81 weak_alias (__libc_sigaction, sigaction)
82 #endif