1 /* Copyright (C) 1997, 1998 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
24 #include <sys/syscall.h>
26 /* The difference here is that the sigaction structure used in the
27 kernel is not the same as we use in the libc. Therefore we must
29 #include <kernel_sigaction.h>
31 extern int __syscall_sigaction (int, const struct old_kernel_sigaction
*,
32 struct old_kernel_sigaction
*);
33 extern int __syscall_rt_sigaction (int, const struct kernel_sigaction
*,
34 struct kernel_sigaction
*, size_t);
36 /* The variable is shared between all wrappers around signal handling
37 functions which have RT equivalents. */
38 int __libc_missing_rt_sigs
;
41 /* If ACT is not NULL, change the action for SIG to *ACT.
42 If OACT is not NULL, put the old action for SIG in *OACT. */
44 __sigaction (sig
, act
, oact
)
46 const struct sigaction
*act
;
47 struct sigaction
*oact
;
49 struct old_kernel_sigaction k_sigact
, k_osigact
;
52 #ifdef __NR_rt_sigaction
53 /* First try the RT signals. */
54 if (!__libc_missing_rt_sigs
)
56 struct kernel_sigaction kact
, koact
;
57 int saved_errno
= errno
;
61 kact
.k_sa_handler
= act
->sa_handler
;
62 memcpy (&kact
.sa_mask
, &act
->sa_mask
, sizeof (sigset_t
));
63 kact
.sa_flags
= act
->sa_flags
;
64 # ifdef HAVE_SA_RESTORER
65 kact
.sa_restorer
= act
->sa_restorer
;
69 /* XXX The size argument hopefully will have to be changed to the
70 real size of the user-level sigset_t. */
71 result
= INLINE_SYSCALL (rt_sigaction
, 4, sig
, act
? &kact
: NULL
,
72 oact
? &koact
: NULL
, _NSIG
/ 8);
74 if (result
>= 0 || errno
!= ENOSYS
)
76 if (oact
&& result
>= 0)
78 oact
->sa_handler
= koact
.k_sa_handler
;
79 memcpy (&oact
->sa_mask
, &koact
.sa_mask
, sizeof (sigset_t
));
80 oact
->sa_flags
= koact
.sa_flags
;
81 # ifdef HAVE_SA_RESTORER
82 oact
->sa_restorer
= koact
.sa_restorer
;
88 __set_errno (saved_errno
);
89 __libc_missing_rt_sigs
= 1;
95 k_sigact
.k_sa_handler
= act
->sa_handler
;
96 k_sigact
.sa_mask
= act
->sa_mask
.__val
[0];
97 k_sigact
.sa_flags
= act
->sa_flags
;
98 #ifdef HAVE_SA_RESTORER
99 k_sigact
.sa_restorer
= act
->sa_restorer
;
102 result
= INLINE_SYSCALL (sigaction
, 3, sig
, act
? &k_sigact
: NULL
,
103 oact
? &k_osigact
: NULL
);
104 if (oact
&& result
>= 0)
106 oact
->sa_handler
= k_osigact
.k_sa_handler
;
107 oact
->sa_mask
.__val
[0] = k_osigact
.sa_mask
;
108 oact
->sa_flags
= k_osigact
.sa_flags
;
109 #ifdef HAVE_SA_RESTORER
110 oact
->sa_restorer
= k_osigact
.sa_restorer
;
116 weak_alias (__sigaction
, sigaction
)