]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/signal/sigaction.c
Inital import
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / signal / sigaction.c
1 /* Copyright (C) 1997-2000,2002,2003,2005,2006 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, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #include <features.h>
20 #include <errno.h>
21 #include <signal.h>
22 #include <string.h>
23 #include <sys/syscall.h>
24
25 #include <bits/kernel_sigaction.h>
26
27 #ifndef LIBC_SIGACTION
28 extern __typeof(sigaction) __libc_sigaction;
29 #endif
30
31
32 #if defined __NR_rt_sigaction
33
34 /* If ACT is not NULL, change the action for SIG to *ACT.
35    If OACT is not NULL, put the old action for SIG in *OACT.  */
36 int
37 __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
38 {
39         /* NB: kernel (as of 2.6.25) will return EINVAL
40          * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t).
41          * Try to catch this problem at uclibc build time:  */
42         struct BUG_sigset_size {
43                 int BUG_sigset_size
44                         [sizeof(act->sa_mask) == _NSIG / 8 ? 1 : -1];
45         };
46         return __syscall_rt_sigaction(sig, act, oact, sizeof(act->sa_mask));
47 }
48
49 #else
50
51 /* If ACT is not NULL, change the action for SIG to *ACT.
52    If OACT is not NULL, put the old action for SIG in *OACT.  */
53 int
54 __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
55 {
56         int result;
57         struct old_kernel_sigaction kact, koact;
58
59         if (act) {
60                 kact.k_sa_handler = act->sa_handler;
61                 kact.sa_mask = act->sa_mask.__val[0];
62                 kact.sa_flags = act->sa_flags;
63 # ifdef HAVE_SA_RESTORER
64                 kact.sa_restorer = act->sa_restorer;
65 # endif
66         }
67         result = __syscall_sigaction(sig,
68                         act ? &kact : NULL,
69                         oact ? &koact : NULL);
70         if (oact && result >= 0) {
71                 oact->sa_handler = koact.k_sa_handler;
72                 oact->sa_mask.__val[0] = koact.sa_mask;
73                 oact->sa_flags = koact.sa_flags;
74 # ifdef HAVE_SA_RESTORER
75                 oact->sa_restorer = koact.sa_restorer;
76 # endif
77         }
78         return result;
79 }
80
81 #endif
82
83
84 #ifndef LIBC_SIGACTION
85 weak_alias(__libc_sigaction,sigaction)
86 libc_hidden_weak(sigaction)
87 #endif