]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sigaction.c
c8694c17e31113ec0b2c54d54daa128efca11df0
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sigaction.c
1 /* Copyright (C) 1997-2014 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 /* The difference here is that the sigaction structure used in the
26 kernel is not the same as we use in the libc. Therefore we must
27 translate it here. */
28 #include <kernel_sigaction.h>
29
30
31 /* If ACT is not NULL, change the action for SIG to *ACT.
32 If OACT is not NULL, put the old action for SIG in *OACT. */
33 int
34 __libc_sigaction (sig, act, oact)
35 int sig;
36 const struct sigaction *act;
37 struct sigaction *oact;
38 {
39 int result;
40
41 struct kernel_sigaction kact, koact;
42
43 if (act)
44 {
45 kact.k_sa_handler = act->sa_handler;
46 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
47 kact.sa_flags = act->sa_flags;
48 #ifdef HAVE_SA_RESTORER
49 kact.sa_restorer = act->sa_restorer;
50 #endif
51 }
52
53 /* XXX The size argument hopefully will have to be changed to the
54 real size of the user-level sigset_t. */
55 result = INLINE_SYSCALL (rt_sigaction, 4, sig,
56 act ? &kact : NULL,
57 oact ? &koact : NULL, _NSIG / 8);
58
59 if (oact && result >= 0)
60 {
61 oact->sa_handler = koact.k_sa_handler;
62 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
63 oact->sa_flags = koact.sa_flags;
64 #ifdef HAVE_SA_RESTORER
65 oact->sa_restorer = koact.sa_restorer;
66 #endif
67 }
68 return result;
69 }
70 libc_hidden_def (__libc_sigaction)
71
72 #include <nptl/sigaction.c>