Remove *xattr syscalls.
[glibc.git] / sysdeps / posix / sigvec.c
blobd5f7ccdb4a164c57992d26ca4e1833b602b88973
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 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
17 02111-1307 USA. */
19 #include <signal.h>
20 #include <errno.h>
21 #include <stddef.h>
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;
30 unsigned int sw_mask;
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. */
43 int
44 __sigvec (sig, vec, ovec)
45 int sig;
46 const struct sigvec *vec;
47 struct sigvec *ovec;
49 struct sigaction old;
51 if (vec == NULL || !(vec->sv_flags & SV_RESETHAND))
53 struct sigaction new, *n;
55 if (vec == NULL)
56 n = NULL;
57 else
59 __sighandler_t handler;
60 unsigned int mask;
61 unsigned int sv_flags;
62 unsigned int sa_flags;
64 handler = vec->sv_handler;
65 mask = vec->sv_mask;
66 sv_flags = vec->sv_flags;
67 sa_flags = 0;
68 if (sv_flags & SV_ONSTACK)
70 #ifdef SA_ONSTACK
71 sa_flags |= SA_ONSTACK;
72 #else
73 __set_errno (ENOSYS);
74 return -1;
75 #endif
77 #ifdef SA_RESTART
78 if (!(sv_flags & SV_INTERRUPT))
79 sa_flags |= SA_RESTART;
80 #endif
81 n = &new;
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)
88 return -1;
90 else
92 __sighandler_t handler;
93 unsigned int mask;
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)
106 return -1;
109 if (ovec != NULL)
111 __sighandler_t handler;
112 unsigned int sv_flags;
113 unsigned int sa_flags;
114 unsigned int mask;
116 handler = old.sa_handler;
117 sv_flags = 0;
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);
126 #ifdef SA_ONSTACK
127 if (sa_flags & SA_ONSTACK)
128 sv_flags |= SV_ONSTACK;
129 #endif
130 #ifdef SA_RESTART
131 if (!(sa_flags & SA_RESTART))
132 #endif
133 sv_flags |= SV_INTERRUPT;
134 ovec->sv_handler = handler;
135 ovec->sv_mask = (int)mask;
136 ovec->sv_flags = (int)sv_flags;
139 return 0;
142 weak_alias (__sigvec, sigvec)
145 static void
146 sigvec_wrapper_handler (sig)
147 int sig;
149 struct sigvec_wrapper_data *data;
150 unsigned int mask;
151 struct sigaction act;
152 int save;
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);
159 act.sa_flags = 0;
160 save = errno;
161 handler = data->sw_handler;
162 (void) __sigaction (sig, &act, (struct sigaction *) NULL);
163 __set_errno (save);
164 (*handler) (sig);