1 /* Copyright (C) 1991-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/>. */
22 /* Include macros to convert between `sigset_t' and old-style mask. */
23 #include <sigset-cvt-mask.h>
26 /* When sigaction lacks the extension bit for it,
27 we use a wrapper handler to support SV_RESETHAND. */
28 struct sigvec_wrapper_data
30 __sighandler_t sw_handler
;
34 static void sigvec_wrapper_handler (int sig
) __THROW
;
36 static struct sigvec_wrapper_data sigvec_wrapper_data
[NSIG
];
40 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
41 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
42 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
43 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
44 it is filled in with the old information for SIG. */
46 __sigvec (sig
, vec
, ovec
)
48 const struct sigvec
*vec
;
54 if (vec
== NULL
|| !(vec
->sv_flags
& SV_RESETHAND
))
57 struct sigaction
new, *n
;
63 __sighandler_t handler
;
65 unsigned int sv_flags
;
66 unsigned int sa_flags
;
68 handler
= vec
->sv_handler
;
70 sv_flags
= vec
->sv_flags
;
72 if (sv_flags
& SV_ONSTACK
)
75 sa_flags
|= SA_ONSTACK
;
82 if (!(sv_flags
& SV_INTERRUPT
))
83 sa_flags
|= SA_RESTART
;
86 if (sv_flags
& SV_RESETHAND
)
87 sa_flags
|= SA_RESETHAND
;
90 new.sa_handler
= handler
;
91 if (sigset_set_old_mask (&new.sa_mask
, mask
) < 0)
93 new.sa_flags
= sa_flags
;
96 if (__sigaction (sig
, n
, &old
) < 0)
102 __sighandler_t handler
;
104 struct sigvec_wrapper_data
*data
;
105 struct sigaction wrapper
;
107 handler
= vec
->sv_handler
;
108 mask
= (unsigned int)vec
->sv_mask
;
109 data
= &sigvec_wrapper_data
[sig
];
110 wrapper
.sa_handler
= sigvec_wrapper_handler
;
111 /* FIXME: should we set wrapper.sa_mask, wrapper.sa_flags?? */
112 data
->sw_handler
= handler
;
113 data
->sw_mask
= mask
;
115 if (__sigaction (sig
, &wrapper
, &old
) < 0)
122 __sighandler_t handler
;
123 unsigned int sv_flags
;
124 unsigned int sa_flags
;
127 handler
= old
.sa_handler
;
129 sa_flags
= old
.sa_flags
;
131 if (handler
== sigvec_wrapper_handler
)
133 handler
= sigvec_wrapper_data
[sig
].sw_handler
;
134 /* should we use data->sw_mask?? */
135 sv_flags
|= SV_RESETHAND
;
138 if (sa_flags
& SA_RESETHAND
)
139 sv_flags
|= SV_RESETHAND
;
141 mask
= sigset_get_old_mask (&old
.sa_mask
);
143 if (sa_flags
& SA_ONSTACK
)
144 sv_flags
|= SV_ONSTACK
;
147 if (!(sa_flags
& SA_RESTART
))
149 sv_flags
|= SV_INTERRUPT
;
150 ovec
->sv_handler
= handler
;
151 ovec
->sv_mask
= (int)mask
;
152 ovec
->sv_flags
= (int)sv_flags
;
158 weak_alias (__sigvec
, sigvec
)
162 sigvec_wrapper_handler (sig
)
165 struct sigvec_wrapper_data
*data
;
166 struct sigaction act
;
168 __sighandler_t handler
;
170 data
= &sigvec_wrapper_data
[sig
];
171 act
.sa_handler
= SIG_DFL
;
173 sigset_set_old_mask (&act
.sa_mask
, data
->sw_mask
);
174 handler
= data
->sw_handler
;
176 (void) __sigaction (sig
, &act
, (struct sigaction
*) NULL
);