2 * sigact.c - fake sigaction(2)
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);
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"
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
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':
47 * void (*sa_handler)();
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
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
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
97 * 0==success, -1==failure
100 * Since we fake most of this, don't expect fancy usage to
104 * Simon J. Gerraty <sjg@zen.void.oz.au>
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
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:
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.
147 # if defined(__STDC__) || defined(__cplusplus)
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.
166 #if defined(__AROS__)
167 sigaction(int sig
, const struct sigaction
*act
, struct sigaction
*oact
)
169 sigaction(int sig
, struct sigaction
*act
, struct sigaction
*oact
)
176 oldh
= signal(sig
, act
->sa_handler
);
182 oldh
= signal(sig
, SIG_IGN
);
183 if (oldh
!= SIG_IGN
&& oldh
!= SIG_ERR
)
185 (void) signal(sig
, oldh
);
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
);
204 sigemptyset(sigset_t
*mask
)
211 #if !defined(CLIB2) && !defined(__AROS__)
213 sigprocmask(int how
, const sigset_t
*set
, sigset_t
*oset
)
221 * initally we clear sm,
222 * there after, it represents the last
253 #if !defined(SIG_ERR)
254 # define SIG_ERR (void (*)())-1