1 /* Copyright (C) 1991,92,94,95,96,97,98,2002 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 /* Include macros to convert between `sigset_t' and old-style mask. */
24 #include <sigset-cvt-mask.h>
27 /* When sigaction lacks the extension bit for it,
28 we use a wrapper handler to support SV_RESETHAND. */
29 struct sigvec_wrapper_data
31 __sighandler_t sw_handler
;
35 static void sigvec_wrapper_handler
__P ((int sig
));
37 static struct sigvec_wrapper_data sigvec_wrapper_data
[NSIG
];
41 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
42 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
43 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
44 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
45 it is filled in with the old information for SIG. */
47 __sigvec (sig
, vec
, ovec
)
49 const struct sigvec
*vec
;
55 if (vec
== NULL
|| !(vec
->sv_flags
& SV_RESETHAND
))
58 struct sigaction
new, *n
;
64 __sighandler_t handler
;
66 unsigned int sv_flags
;
67 unsigned int sa_flags
;
69 handler
= vec
->sv_handler
;
71 sv_flags
= vec
->sv_flags
;
73 if (sv_flags
& SV_ONSTACK
)
76 sa_flags
|= SA_ONSTACK
;
83 if (!(sv_flags
& SV_INTERRUPT
))
84 sa_flags
|= SA_RESTART
;
87 if (sv_flags
& SV_RESETHAND
)
88 sa_flags
|= SA_RESETHAND
;
91 new.sa_handler
= handler
;
92 if (sigset_set_old_mask (&new.sa_mask
, mask
) < 0)
94 new.sa_flags
= sa_flags
;
97 if (__sigaction (sig
, n
, &old
) < 0)
103 __sighandler_t handler
;
105 struct sigvec_wrapper_data
*data
;
106 struct sigaction wrapper
;
108 handler
= vec
->sv_handler
;
109 mask
= (unsigned int)vec
->sv_mask
;
110 data
= &sigvec_wrapper_data
[sig
];
111 wrapper
.sa_handler
= sigvec_wrapper_handler
;
112 /* FIXME: should we set wrapper.sa_mask, wrapper.sa_flags?? */
113 data
->sw_handler
= handler
;
114 data
->sw_mask
= mask
;
116 if (__sigaction (sig
, &wrapper
, &old
) < 0)
123 __sighandler_t handler
;
124 unsigned int sv_flags
;
125 unsigned int sa_flags
;
128 handler
= old
.sa_handler
;
130 sa_flags
= old
.sa_flags
;
132 if (handler
== sigvec_wrapper_handler
)
134 handler
= sigvec_wrapper_data
[sig
].sw_handler
;
135 /* should we use data->sw_mask?? */
136 sv_flags
|= SV_RESETHAND
;
139 if (sa_flags
& SA_RESETHAND
)
140 sv_flags
|= SV_RESETHAND
;
142 mask
= sigset_get_old_mask (&old
.sa_mask
);
144 if (sa_flags
& SA_ONSTACK
)
145 sv_flags
|= SV_ONSTACK
;
148 if (!(sa_flags
& SA_RESTART
))
150 sv_flags
|= SV_INTERRUPT
;
151 ovec
->sv_handler
= handler
;
152 ovec
->sv_mask
= (int)mask
;
153 ovec
->sv_flags
= (int)sv_flags
;
159 weak_alias (__sigvec
, sigvec
)
163 sigvec_wrapper_handler (sig
)
166 struct sigvec_wrapper_data
*data
;
167 struct sigaction act
;
169 __sighandler_t handler
;
171 data
= &sigvec_wrapper_data
[sig
];
172 act
.sa_handler
= SIG_DFL
;
174 sigset_set_old_mask (&act
.sa_mask
, data
->sw_mask
);
175 handler
= data
->sw_handler
;
177 (void) __sigaction (sig
, &act
, (struct sigaction
*) NULL
);