reenabled swaptest. quake should now load data and start on big endian architectures...
[AROS-Contrib.git] / gnu / abc-shell / sigact.c
blobd3c86d1d144d03ef7c37ceb91012dd97de9a09b6
1 /* NAME:
2 * sigact.c - fake sigaction(2)
4 * SYNOPSIS:
5 * #include "sigact.h"
6 *
7 * int sigaction(int sig, struct sigaction *act,
8 * struct sigaction *oact);
9 * int sigaddset(sigset_t *mask, int sig);
10 * int sigdelset(sigset_t *mask, int sig);
11 * int sigemptyset(sigset_t *mask);
12 * int sigfillset(sigset_t *mask);
13 * int sigismember(sigset_t *mask, int sig);
14 * int sigpending(sigset_t *set);
15 * int sigprocmask(int how, sigset_t *set, sigset_t *oset);
16 * int sigsuspend(sigset_t *mask);
18 * void (*_Signal(int sig, void (*disp)(int)))(int);
20 * DESCRIPTION:
21 * This is a fake sigaction implementation. It uses
22 * sigsetmask(2) et al or sigset(2) and friends if
23 * available, otherwise it just uses signal(2). If it
24 * thinks sigaction(2) really exists it compiles to "almost"
25 * nothing.
27 * In any case it provides a _Signal() function that is
28 * implemented in terms of sigaction().
29 * If not using signal(2) as part of the underlying
30 * implementation (USE_SIGNAL or USE_SIGMASK), and
31 * NO_SIGNAL is not defined, it also provides a signal()
32 * function that calls _Signal().
34 * The need for all this mucking about is the problems
35 * caused by mixing various signal handling mechanisms in
36 * the one process. This module allows for a consistent
37 * POSIX compliant interface to whatever is actually
38 * available.
40 * sigaction() allows the caller to examine and/or set the
41 * action to be associated with a given signal. "act" and
42 * "oact" are pointers to 'sigaction structs':
43 *.nf
45 * struct sigaction
46 * {
47 * void (*sa_handler)();
48 * sigset_t sa_mask;
49 * int sa_flags;
50 * };
51 *.fi
53 * void is normally 'void' in the POSIX implementation
54 * and for most current systems. On some older UNIX
55 * systems, signal handlers do not return 'void', so
56 * this implementation keeps 'sa_handler' inline with the
57 * hosts normal signal handling conventions.
58 * 'sa_mask' controls which signals will be blocked while
59 * the selected signal handler is active. It is not used
60 * in this implementation.
61 * 'sa_flags' controls various semantics such as whether
62 * system calls should be automagically restarted
63 * (SA_RESTART) etc. It is not used in this
64 * implementation.
65 * Either "act" or "oact" may be NULL in which case the
66 * appropriate operation is skipped.
68 * sigaddset() adds "sig" to the sigset_t pointed to by "mask".
70 * sigdelset() removes "sig" from the sigset_t pointed to
71 * by "mask".
73 * sigemptyset() makes the sigset_t pointed to by "mask" empty.
75 * sigfillset() makes the sigset_t pointed to by "mask"
76 * full ie. match all signals.
78 * sigismember() returns true if "sig" is found in "*mask".
80 * sigpending() is supposed to return "set" loaded with the
81 * set of signals that are blocked and pending for the
82 * calling process. It does nothing in this impementation.
84 * sigprocmask() is used to examine and/or change the
85 * signal mask for the calling process. Either "set" or
86 * "oset" may be NULL in which case the appropriate
87 * operation is skipped. "how" may be one of SIG_BLOCK,
88 * SIG_UNBLOCK or SIG_SETMASK. If this package is built
89 * with USE_SIGNAL, then this routine achieves nothing.
91 * sigsuspend() sets the signal mask to "*mask" and waits
92 * for a signal to be delivered after which the previous
93 * mask is restored.
96 * RETURN VALUE:
97 * 0==success, -1==failure
99 * BUGS:
100 * Since we fake most of this, don't expect fancy usage to
101 * work.
103 * AUTHOR:
104 * Simon J. Gerraty <sjg@zen.void.oz.au>
106 /* COPYRIGHT:
107 * @(#)Copyright (c) 1992 Simon J. Gerraty
109 * This is free software. It comes with NO WARRANTY.
110 * Permission to use, modify and distribute this source code
111 * is granted subject to the following conditions.
112 * 1/ that that the above copyright notice and this notice
113 * are preserved in all copies and that due credit be given
114 * to the author.
115 * 2/ that any changes to this code are clearly commented
116 * as such so that the author does get blamed for bugs
117 * other than his own.
119 * Please send copies of changes and bug-fixes to:
120 * sjg@zen.void.oz.au
123 /* Changes to sigact.c for pdksh, Michael Rendell <michael@cs.mun.ca>:
124 * - sigsuspend(): pass *mask to bsd4.2 sigpause instead of mask.
125 * - changed SIG_HDLR to void for use with GNU autoconf
126 * - include sh.h instead of signal.h (to get *_SIGNALS macros)
127 * - changed if !SA_NOCLDSTOP ... to USE_FAKE_SIGACT to avoid confusion
128 * - set the USE_* defines using the *_SIGNALS defines from autoconf
129 * - sigaction(): if using BSD signals, use sigvec() (used to use
130 * signal()) and set the SV_INTERRUPT flag (POSIX says syscalls
131 * are interrupted and pdksh needs this behaviour).
132 * - define IS_KSH before including anything; ifdef out routines
133 * not used in ksh if IS_KSH is defined (same in sigact.h).
134 * - use ARGS() instead of __P()
135 * - sigaction(),sigsuspend(),_Signal(),signal(): use handler_t typedef
136 * instead of explicit type.
140 #include <signal.h>
142 #define IS_KSH
143 #include "sh.h"
146 #ifndef __P
147 # if defined(__STDC__) || defined(__cplusplus)
148 # define __P(p) p
149 # else
150 # define __P(p) ()
151 # endif
152 #endif
157 * some systems have a faulty sigaction() implementation!
158 * Allow us to bypass it.
159 * Or they may have installed sigact.h as signal.h which is why
160 * we have SA_NOCLDSTOP defined.
163 #include "sigact.h"
166 #if defined(__AROS__)
167 sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
168 #else
169 sigaction(int sig, struct sigaction *act, struct sigaction *oact)
170 #endif
172 handler_t oldh;
174 if (act)
176 oldh = signal(sig, act->sa_handler);
178 else
180 if (oact)
182 oldh = signal(sig, SIG_IGN);
183 if (oldh != SIG_IGN && oldh != SIG_ERR)
185 (void) signal(sig, oldh);
189 if (oact)
191 oact->sa_handler = oldh;
193 return 0; /* hey we're faking it */
196 #if !defined(NEWLIB) && !defined(__AROS__)
197 int sigaddset(sigset_t *mask, int sig)
199 *mask |= sigmask(sig);
200 return 0;
204 sigemptyset(sigset_t *mask)
206 *mask = 0;
207 return 0;
209 #endif
211 #if !defined(CLIB2) && !defined(__AROS__)
213 sigprocmask(int how, const sigset_t *set, sigset_t *oset)
215 static sigset_t sm;
216 static int once = 0;
218 if (!once)
221 * initally we clear sm,
222 * there after, it represents the last
223 * thing we did.
225 once++;
226 sm = 0;
229 if (oset)
230 *oset = sm;
231 if (set)
233 switch (how)
235 case SIG_BLOCK:
236 sm |= *set;
237 break;
238 case SIG_UNBLOCK:
239 sm &= ~(*set);
240 break;
241 case SIG_SETMASK:
242 sm = *set;
243 break;
246 return 0;
248 #endif
250 #if !defined(void)
251 # define void void
252 #endif
253 #if !defined(SIG_ERR)
254 # define SIG_ERR (void (*)())-1
255 #endif