1 /* Copyright (C) 1991, 92, 94, 95, 96, 97, 98 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. */
23 /* Include macros to convert between `sigset_t' and old-style mask. */
24 #include "sigset-cvt-mask.h"
26 /* We use a wrapper handler to support SV_RESETHAND. */
27 struct sigvec_wrapper_data
29 __sighandler_t sw_handler
;
33 static void sigvec_wrapper_handler
__P ((int sig
));
35 static struct sigvec_wrapper_data sigvec_wrapper_data
[NSIG
];
38 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
39 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
40 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
41 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
42 it is filled in with the old information for SIG. */
44 __sigvec (sig
, vec
, ovec
)
46 const struct sigvec
*vec
;
51 if (vec
== NULL
|| !(vec
->sv_flags
& SV_RESETHAND
))
53 struct sigaction
new, *n
;
59 __sighandler_t handler
;
61 unsigned int sv_flags
;
62 unsigned int sa_flags
;
64 handler
= vec
->sv_handler
;
66 sv_flags
= vec
->sv_flags
;
68 if (sv_flags
& SV_ONSTACK
)
71 sa_flags
|= SA_ONSTACK
;
78 if (!(sv_flags
& SV_INTERRUPT
))
79 sa_flags
|= SA_RESTART
;
82 new.sa_handler
= handler
;
83 sigset_set_old_mask (&new.sa_mask
, mask
);
84 new.sa_flags
= sa_flags
;
87 if (__sigaction (sig
, n
, &old
) < 0)
92 __sighandler_t handler
;
94 struct sigvec_wrapper_data
*data
;
95 struct sigaction wrapper
;
97 handler
= vec
->sv_handler
;
98 mask
= (unsigned int)vec
->sv_mask
;
99 data
= &sigvec_wrapper_data
[sig
];
100 wrapper
.sa_handler
= sigvec_wrapper_handler
;
101 /* FIXME: should we set wrapper.sa_mask, wrapper.sa_flags?? */
102 data
->sw_handler
= handler
;
103 data
->sw_mask
= mask
;
105 if (__sigaction (sig
, &wrapper
, &old
) < 0)
111 __sighandler_t handler
;
112 unsigned int sv_flags
;
113 unsigned int sa_flags
;
116 handler
= old
.sa_handler
;
118 sa_flags
= old
.sa_flags
;
119 if (handler
== sigvec_wrapper_handler
)
121 handler
= sigvec_wrapper_data
[sig
].sw_handler
;
122 /* should we use data->sw_mask?? */
123 sv_flags
|= SV_RESETHAND
;
125 sigset_get_old_mask (&old
.sa_mask
, mask
);
127 if (sa_flags
& SA_ONSTACK
)
128 sv_flags
|= SV_ONSTACK
;
131 if (!(sa_flags
& SA_RESTART
))
133 sv_flags
|= SV_INTERRUPT
;
134 ovec
->sv_handler
= handler
;
135 ovec
->sv_mask
= (int)mask
;
136 ovec
->sv_flags
= (int)sv_flags
;
142 weak_alias (__sigvec
, sigvec
)
146 sigvec_wrapper_handler (sig
)
149 struct sigvec_wrapper_data
*data
;
151 struct sigaction act
;
153 __sighandler_t handler
;
155 data
= &sigvec_wrapper_data
[sig
];
156 mask
= data
->sw_mask
;
157 act
.sa_handler
= SIG_DFL
;
158 sigset_set_old_mask (&act
.sa_mask
, mask
);
161 handler
= data
->sw_handler
;
162 (void) __sigaction (sig
, &act
, (struct sigaction
*) NULL
);