1 /* Copyright (C) 1991, 92, 94, 95, 96 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 /* We use a wrapper handler to support SV_RESETHAND. */
26 static __sighandler_t wrapped_handlers[NSIG];
27 static sigset_t wrapped_masks[NSIG];
29 static void wrapper_handler __P ((int sig));
30 static inline int convert_mask __P ((sigset_t *set, const int mask));
39 act.sa_handler = SIG_DFL;
40 act.sa_mask = wrapped_masks[sig];
43 (void) __sigaction (sig, &act, (struct sigaction *) NULL);
46 (*wrapped_handlers[sig]) (sig);
50 convert_mask (set, mask)
56 if (sizeof (*set) == sizeof (mask))
58 else if (sizeof (*set) == sizeof (unsigned long int))
59 *(unsigned long int *) set = (unsigned int) mask;
62 if (__sigemptyset (set) < 0)
65 for (sig = 1; sig < NSIG; ++sig)
66 if ((mask & sigmask (sig)) && __sigaddset (set, sig) < 0)
73 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
74 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
75 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
76 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
77 it is filled in with the old information for SIG. */
79 __sigvec (sig, vec, ovec)
81 const struct sigvec *vec;
86 if (vec == NULL || !(vec->sv_flags & SV_RESETHAND))
88 struct sigaction new, *n;
95 n->sa_handler = vec->sv_handler;
96 if (convert_mask (&n->sa_mask, vec->sv_mask) < 0)
100 if (vec->sv_flags & SV_ONSTACK)
103 n->sa_flags |= SA_ONSTACK;
105 __set_errno (ENOSYS);
110 if (!(vec->sv_flags & SV_INTERRUPT))
111 n->sa_flags |= SA_RESTART;
115 if (__sigaction (sig, n, &old) < 0)
120 struct sigaction wrapper;
122 wrapper.sa_handler = wrapper_handler;
123 wrapped_handlers[sig] = vec->sv_handler;
124 if (convert_mask (&wrapped_masks[sig], vec->sv_mask) < 0)
127 if (__sigaction (sig, &wrapper, &old) < 0)
136 if (sizeof (int) == sizeof (sigset_t))
137 mask = *(int *) &old.sa_mask;
138 else if (sizeof (unsigned long int) == sizeof (sigset_t))
139 mask = *(unsigned long int *) &old.sa_mask;
141 for (i = 1; i < NSIG; ++i)
142 if (__sigismember(&old.sa_mask, i))
145 ovec->sv_mask = mask;
148 if (old.sa_flags & SA_ONSTACK)
149 ovec->sv_flags |= SV_ONSTACK;
152 if (!(old.sa_flags & SA_RESTART))
154 ovec->sv_flags |= SV_INTERRUPT;
155 if (old.sa_handler == wrapper_handler)
157 ovec->sv_flags |= SV_RESETHAND;
158 ovec->sv_handler = wrapped_handlers[sig];
161 ovec->sv_handler = old.sa_handler;
167 weak_alias (__sigvec, sigvec)