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>
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 if (sigset_set_old_mask (&new.sa_mask, mask) < 0)
85 new.sa_flags = sa_flags;
88 if (__sigaction (sig, n, &old) < 0)
93 __sighandler_t handler;
95 struct sigvec_wrapper_data *data;
96 struct sigaction wrapper;
98 handler = vec->sv_handler;
99 mask = (unsigned int)vec->sv_mask;
100 data = &sigvec_wrapper_data[sig];
101 wrapper.sa_handler = sigvec_wrapper_handler;
102 /* FIXME: should we set wrapper.sa_mask, wrapper.sa_flags?? */
103 data->sw_handler = handler;
104 data->sw_mask = mask;
106 if (__sigaction (sig, &wrapper, &old) < 0)
112 __sighandler_t handler;
113 unsigned int sv_flags;
114 unsigned int sa_flags;
117 handler = old.sa_handler;
119 sa_flags = old.sa_flags;
120 if (handler == sigvec_wrapper_handler)
122 handler = sigvec_wrapper_data[sig].sw_handler;
123 /* should we use data->sw_mask?? */
124 sv_flags |= SV_RESETHAND;
126 mask = sigset_get_old_mask (&old.sa_mask);
128 if (sa_flags & SA_ONSTACK)
129 sv_flags |= SV_ONSTACK;
132 if (!(sa_flags & SA_RESTART))
134 sv_flags |= SV_INTERRUPT;
135 ovec->sv_handler = handler;
136 ovec->sv_mask = (int)mask;
137 ovec->sv_flags = (int)sv_flags;
143 weak_alias (__sigvec, sigvec)
147 sigvec_wrapper_handler (sig)
150 struct sigvec_wrapper_data *data;
151 struct sigaction act;
153 __sighandler_t handler;
155 data = &sigvec_wrapper_data[sig];
156 act.sa_handler = SIG_DFL;
158 sigset_set_old_mask (&act.sa_mask, data->sw_mask);
159 handler = data->sw_handler;
161 (void) __sigaction (sig, &act, (struct sigaction *) NULL);