1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
24*7c478bd9Sstevel@tonic-gate
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
28*7c478bd9Sstevel@tonic-gate * The Regents of the University of California
29*7c478bd9Sstevel@tonic-gate * All Rights Reserved
30*7c478bd9Sstevel@tonic-gate *
31*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
32*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
33*7c478bd9Sstevel@tonic-gate * contributors.
34*7c478bd9Sstevel@tonic-gate */
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate * mailx -- a modified version of a University of California at Berkeley
40*7c478bd9Sstevel@tonic-gate * mail program
41*7c478bd9Sstevel@tonic-gate */
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate * This code is only compiled in if SIG_HOLD is not defined!
45*7c478bd9Sstevel@tonic-gate *
46*7c478bd9Sstevel@tonic-gate * Retrofit new signal interface to old signal primitives.
47*7c478bd9Sstevel@tonic-gate * Supported routines:
48*7c478bd9Sstevel@tonic-gate * sigsys(sig, func)
49*7c478bd9Sstevel@tonic-gate * sigset(sig, func)
50*7c478bd9Sstevel@tonic-gate * sighold(sig)
51*7c478bd9Sstevel@tonic-gate * sigrelse(sig)
52*7c478bd9Sstevel@tonic-gate * sigignore(sig)
53*7c478bd9Sstevel@tonic-gate * sigpause(sig)
54*7c478bd9Sstevel@tonic-gate * Also,
55*7c478bd9Sstevel@tonic-gate * sigchild()
56*7c478bd9Sstevel@tonic-gate * to set all held signals to ignored signals in the
57*7c478bd9Sstevel@tonic-gate * child process after fork(2)
58*7c478bd9Sstevel@tonic-gate */
59*7c478bd9Sstevel@tonic-gate #include <signal.h>
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate #ifndef SIG_HOLD
62*7c478bd9Sstevel@tonic-gate # include <errno.h>
63*7c478bd9Sstevel@tonic-gate # include <setjmp.h>
64*7c478bd9Sstevel@tonic-gate # include <stdio.h>
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate extern int errno;
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate typedef void (*sigtype)();
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate #define SIG_HOLD ((sigtype) 2)
71*7c478bd9Sstevel@tonic-gate #ifndef SIG_ERR
72*7c478bd9Sstevel@tonic-gate # define SIG_ERR ((sigtype) -1)
73*7c478bd9Sstevel@tonic-gate #endif
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate sigtype sigdisp(), sighold(), sigignore();
76*7c478bd9Sstevel@tonic-gate void _Sigtramp();
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gate /*
79*7c478bd9Sstevel@tonic-gate * The following helps us keep the extended signal semantics together.
80*7c478bd9Sstevel@tonic-gate * We remember for each signal the address of the function we're
81*7c478bd9Sstevel@tonic-gate * supposed to call. s_func is SIG_DFL / SIG_IGN if appropriate.
82*7c478bd9Sstevel@tonic-gate */
83*7c478bd9Sstevel@tonic-gate static struct sigtable {
84*7c478bd9Sstevel@tonic-gate sigtype s_func; /* What to call */
85*7c478bd9Sstevel@tonic-gate int s_flag; /* Signal flags; see below */
86*7c478bd9Sstevel@tonic-gate } sigtable[NSIG + 1];
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate * Signal flag values.
90*7c478bd9Sstevel@tonic-gate */
91*7c478bd9Sstevel@tonic-gate #define SHELD 1 /* Signal is being held */
92*7c478bd9Sstevel@tonic-gate #define SDEFER 2 /* Signal occured while held */
93*7c478bd9Sstevel@tonic-gate #define SSET 4 /* s_func is believable */
94*7c478bd9Sstevel@tonic-gate #define SPAUSE 8 /* are pausing, waiting for sig */
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate jmp_buf _pause; /* For doing sigpause() */
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gate /*
99*7c478bd9Sstevel@tonic-gate * Approximate sigsys() system call
100*7c478bd9Sstevel@tonic-gate * This is almost useless since one only calls sigsys()
101*7c478bd9Sstevel@tonic-gate * in the child of a vfork(). If you have vfork(), you have new signals
102*7c478bd9Sstevel@tonic-gate * anyway. The real sigsys() does all the stuff needed to support
103*7c478bd9Sstevel@tonic-gate * the real sigset() library. We don't bother here, assuming that
104*7c478bd9Sstevel@tonic-gate * you are either ignoring or defaulting a signal in the child.
105*7c478bd9Sstevel@tonic-gate */
106*7c478bd9Sstevel@tonic-gate sigtype
sigsys(int sig,sigtype func)107*7c478bd9Sstevel@tonic-gate sigsys(int sig, sigtype func)
108*7c478bd9Sstevel@tonic-gate {
109*7c478bd9Sstevel@tonic-gate sigtype old;
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate old = sigdisp(sig);
112*7c478bd9Sstevel@tonic-gate signal(sig, func);
113*7c478bd9Sstevel@tonic-gate return(old);
114*7c478bd9Sstevel@tonic-gate }
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gate /*
118*7c478bd9Sstevel@tonic-gate * Set the (permanent) disposition of a signal.
119*7c478bd9Sstevel@tonic-gate * If the signal is subsequently (or even now) held,
120*7c478bd9Sstevel@tonic-gate * the action you set here can be enabled using sigrelse().
121*7c478bd9Sstevel@tonic-gate */
122*7c478bd9Sstevel@tonic-gate sigtype
sigset(int sig,sigtype func)123*7c478bd9Sstevel@tonic-gate sigset(int sig, sigtype func)
124*7c478bd9Sstevel@tonic-gate {
125*7c478bd9Sstevel@tonic-gate sigtype old;
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate if (sig < 1 || sig > NSIG) {
128*7c478bd9Sstevel@tonic-gate errno = EINVAL;
129*7c478bd9Sstevel@tonic-gate return(SIG_ERR);
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate old = sigdisp(sig);
132*7c478bd9Sstevel@tonic-gate /*
133*7c478bd9Sstevel@tonic-gate * Does anyone actually call sigset with SIG_HOLD!?
134*7c478bd9Sstevel@tonic-gate */
135*7c478bd9Sstevel@tonic-gate if (func == SIG_HOLD) {
136*7c478bd9Sstevel@tonic-gate sighold(sig);
137*7c478bd9Sstevel@tonic-gate return(old);
138*7c478bd9Sstevel@tonic-gate }
139*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag |= SSET;
140*7c478bd9Sstevel@tonic-gate sigtable[sig].s_func = func;
141*7c478bd9Sstevel@tonic-gate if (func == SIG_DFL) {
142*7c478bd9Sstevel@tonic-gate /*
143*7c478bd9Sstevel@tonic-gate * If signal has been held, must retain
144*7c478bd9Sstevel@tonic-gate * the catch so that we can note occurrance
145*7c478bd9Sstevel@tonic-gate * of signal.
146*7c478bd9Sstevel@tonic-gate */
147*7c478bd9Sstevel@tonic-gate if ((sigtable[sig].s_flag & SHELD) == 0)
148*7c478bd9Sstevel@tonic-gate signal(sig, SIG_DFL);
149*7c478bd9Sstevel@tonic-gate else
150*7c478bd9Sstevel@tonic-gate signal(sig, _Sigtramp);
151*7c478bd9Sstevel@tonic-gate return(old);
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate if (func == SIG_IGN) {
154*7c478bd9Sstevel@tonic-gate /*
155*7c478bd9Sstevel@tonic-gate * Clear pending signal
156*7c478bd9Sstevel@tonic-gate */
157*7c478bd9Sstevel@tonic-gate signal(sig, SIG_IGN);
158*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag &= ~SDEFER;
159*7c478bd9Sstevel@tonic-gate return(old);
160*7c478bd9Sstevel@tonic-gate }
161*7c478bd9Sstevel@tonic-gate signal(sig, _Sigtramp);
162*7c478bd9Sstevel@tonic-gate return(old);
163*7c478bd9Sstevel@tonic-gate }
164*7c478bd9Sstevel@tonic-gate
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate * Hold a signal.
167*7c478bd9Sstevel@tonic-gate * This CAN be tricky if the signal's disposition is SIG_DFL.
168*7c478bd9Sstevel@tonic-gate * In that case, we still catch the signal so we can note it
169*7c478bd9Sstevel@tonic-gate */
170*7c478bd9Sstevel@tonic-gate sigtype
sighold(int sig)171*7c478bd9Sstevel@tonic-gate sighold(int sig)
172*7c478bd9Sstevel@tonic-gate {
173*7c478bd9Sstevel@tonic-gate sigtype old;
174*7c478bd9Sstevel@tonic-gate
175*7c478bd9Sstevel@tonic-gate if (sig < 1 || sig > NSIG) {
176*7c478bd9Sstevel@tonic-gate errno = EINVAL;
177*7c478bd9Sstevel@tonic-gate return(SIG_ERR);
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate old = sigdisp(sig);
180*7c478bd9Sstevel@tonic-gate if (sigtable[sig].s_flag & SHELD)
181*7c478bd9Sstevel@tonic-gate return(old);
182*7c478bd9Sstevel@tonic-gate /*
183*7c478bd9Sstevel@tonic-gate * When the default action is required, we have to
184*7c478bd9Sstevel@tonic-gate * set up to catch the signal to note signal's occurrance.
185*7c478bd9Sstevel@tonic-gate */
186*7c478bd9Sstevel@tonic-gate if (old == SIG_DFL) {
187*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag |= SSET;
188*7c478bd9Sstevel@tonic-gate signal(sig, _Sigtramp);
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag |= SHELD;
191*7c478bd9Sstevel@tonic-gate return(old);
192*7c478bd9Sstevel@tonic-gate }
193*7c478bd9Sstevel@tonic-gate
194*7c478bd9Sstevel@tonic-gate /*
195*7c478bd9Sstevel@tonic-gate * Release a signal
196*7c478bd9Sstevel@tonic-gate * If the signal occurred while we had it held, cause the signal.
197*7c478bd9Sstevel@tonic-gate */
198*7c478bd9Sstevel@tonic-gate sigtype
sigrelse(int sig)199*7c478bd9Sstevel@tonic-gate sigrelse(int sig)
200*7c478bd9Sstevel@tonic-gate {
201*7c478bd9Sstevel@tonic-gate sigtype old;
202*7c478bd9Sstevel@tonic-gate
203*7c478bd9Sstevel@tonic-gate if (sig < 1 || sig > NSIG) {
204*7c478bd9Sstevel@tonic-gate errno = EINVAL;
205*7c478bd9Sstevel@tonic-gate return(SIG_ERR);
206*7c478bd9Sstevel@tonic-gate }
207*7c478bd9Sstevel@tonic-gate old = sigdisp(sig);
208*7c478bd9Sstevel@tonic-gate if ((sigtable[sig].s_flag & SHELD) == 0)
209*7c478bd9Sstevel@tonic-gate return(old);
210*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag &= ~SHELD;
211*7c478bd9Sstevel@tonic-gate if (sigtable[sig].s_flag & SDEFER)
212*7c478bd9Sstevel@tonic-gate _Sigtramp(sig);
213*7c478bd9Sstevel@tonic-gate /*
214*7c478bd9Sstevel@tonic-gate * If disposition was the default, then we can unset the
215*7c478bd9Sstevel@tonic-gate * catch to _Sigtramp() and let the system do the work.
216*7c478bd9Sstevel@tonic-gate */
217*7c478bd9Sstevel@tonic-gate if (sigtable[sig].s_func == SIG_DFL)
218*7c478bd9Sstevel@tonic-gate signal(sig, SIG_DFL);
219*7c478bd9Sstevel@tonic-gate return(old);
220*7c478bd9Sstevel@tonic-gate }
221*7c478bd9Sstevel@tonic-gate
222*7c478bd9Sstevel@tonic-gate /*
223*7c478bd9Sstevel@tonic-gate * Ignore a signal.
224*7c478bd9Sstevel@tonic-gate */
225*7c478bd9Sstevel@tonic-gate sigtype
sigignore(int sig)226*7c478bd9Sstevel@tonic-gate sigignore(int sig)
227*7c478bd9Sstevel@tonic-gate {
228*7c478bd9Sstevel@tonic-gate return(sigset(sig, SIG_IGN));
229*7c478bd9Sstevel@tonic-gate }
230*7c478bd9Sstevel@tonic-gate
231*7c478bd9Sstevel@tonic-gate /*
232*7c478bd9Sstevel@tonic-gate * Pause, waiting for sig to occur.
233*7c478bd9Sstevel@tonic-gate * We assume LUSER called us with the signal held.
234*7c478bd9Sstevel@tonic-gate * When we got the signal, mark the signal as having
235*7c478bd9Sstevel@tonic-gate * occurred. It will actually cause something when
236*7c478bd9Sstevel@tonic-gate * the signal is released.
237*7c478bd9Sstevel@tonic-gate */
238*7c478bd9Sstevel@tonic-gate int
sigpause(int sig)239*7c478bd9Sstevel@tonic-gate sigpause(int sig)
240*7c478bd9Sstevel@tonic-gate {
241*7c478bd9Sstevel@tonic-gate if (sig < 1 || sig > NSIG) {
242*7c478bd9Sstevel@tonic-gate errno = EINVAL;
243*7c478bd9Sstevel@tonic-gate return;
244*7c478bd9Sstevel@tonic-gate }
245*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag |= SHELD|SPAUSE;
246*7c478bd9Sstevel@tonic-gate if (setjmp(_pause) == 0)
247*7c478bd9Sstevel@tonic-gate pause();
248*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag &= ~SPAUSE;
249*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag |= SDEFER;
250*7c478bd9Sstevel@tonic-gate }
251*7c478bd9Sstevel@tonic-gate
252*7c478bd9Sstevel@tonic-gate /*
253*7c478bd9Sstevel@tonic-gate * In the child process after fork(2), set the disposition of all held
254*7c478bd9Sstevel@tonic-gate * signals to SIG_IGN. This is a new procedure not in the real sigset()
255*7c478bd9Sstevel@tonic-gate * package, provided for retrofitting purposes.
256*7c478bd9Sstevel@tonic-gate */
257*7c478bd9Sstevel@tonic-gate int
sigchild(void)258*7c478bd9Sstevel@tonic-gate sigchild(void)
259*7c478bd9Sstevel@tonic-gate {
260*7c478bd9Sstevel@tonic-gate register int i;
261*7c478bd9Sstevel@tonic-gate
262*7c478bd9Sstevel@tonic-gate for (i = 1; i <= NSIG; i++)
263*7c478bd9Sstevel@tonic-gate if (sigtable[i].s_flag & SHELD)
264*7c478bd9Sstevel@tonic-gate signal(i, SIG_IGN);
265*7c478bd9Sstevel@tonic-gate }
266*7c478bd9Sstevel@tonic-gate
267*7c478bd9Sstevel@tonic-gate
268*7c478bd9Sstevel@tonic-gate /*
269*7c478bd9Sstevel@tonic-gate * Return the current disposition of a signal
270*7c478bd9Sstevel@tonic-gate * If we have not set this signal before, we have to
271*7c478bd9Sstevel@tonic-gate * ask the system
272*7c478bd9Sstevel@tonic-gate */
273*7c478bd9Sstevel@tonic-gate sigtype
sigdisp(int sig)274*7c478bd9Sstevel@tonic-gate sigdisp(int sig)
275*7c478bd9Sstevel@tonic-gate {
276*7c478bd9Sstevel@tonic-gate sigtype old;
277*7c478bd9Sstevel@tonic-gate
278*7c478bd9Sstevel@tonic-gate if (sig < 1 || sig > NSIG) {
279*7c478bd9Sstevel@tonic-gate errno = EINVAL;
280*7c478bd9Sstevel@tonic-gate return(SIG_ERR);
281*7c478bd9Sstevel@tonic-gate }
282*7c478bd9Sstevel@tonic-gate /*
283*7c478bd9Sstevel@tonic-gate * If we have no knowledge of this signal,
284*7c478bd9Sstevel@tonic-gate * ask the system, then save the result for later.
285*7c478bd9Sstevel@tonic-gate */
286*7c478bd9Sstevel@tonic-gate if ((sigtable[sig].s_flag & SSET) == 0) {
287*7c478bd9Sstevel@tonic-gate old = signal(sig, SIG_IGN);
288*7c478bd9Sstevel@tonic-gate sigtable[sig].s_func = old;
289*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag |= SSET;
290*7c478bd9Sstevel@tonic-gate signal(sig, old);
291*7c478bd9Sstevel@tonic-gate return(old);
292*7c478bd9Sstevel@tonic-gate }
293*7c478bd9Sstevel@tonic-gate /*
294*7c478bd9Sstevel@tonic-gate * If we have set this signal before, then sigset()
295*7c478bd9Sstevel@tonic-gate * will have been careful to leave something meaningful
296*7c478bd9Sstevel@tonic-gate * in s_func.
297*7c478bd9Sstevel@tonic-gate */
298*7c478bd9Sstevel@tonic-gate return(sigtable[sig].s_func);
299*7c478bd9Sstevel@tonic-gate }
300*7c478bd9Sstevel@tonic-gate
301*7c478bd9Sstevel@tonic-gate /*
302*7c478bd9Sstevel@tonic-gate * The following routine gets called for any signal
303*7c478bd9Sstevel@tonic-gate * that is to be trapped to a user function.
304*7c478bd9Sstevel@tonic-gate */
305*7c478bd9Sstevel@tonic-gate void
_Sigtramp(int sig)306*7c478bd9Sstevel@tonic-gate _Sigtramp(int sig)
307*7c478bd9Sstevel@tonic-gate {
308*7c478bd9Sstevel@tonic-gate sigtype old;
309*7c478bd9Sstevel@tonic-gate
310*7c478bd9Sstevel@tonic-gate if (sig < 1 || sig > NSIG) {
311*7c478bd9Sstevel@tonic-gate errno = EINVAL;
312*7c478bd9Sstevel@tonic-gate return;
313*7c478bd9Sstevel@tonic-gate }
314*7c478bd9Sstevel@tonic-gate
315*7c478bd9Sstevel@tonic-gate top:
316*7c478bd9Sstevel@tonic-gate old = signal(sig, SIG_IGN);
317*7c478bd9Sstevel@tonic-gate /*
318*7c478bd9Sstevel@tonic-gate * If signal being paused on, wakeup sigpause()
319*7c478bd9Sstevel@tonic-gate */
320*7c478bd9Sstevel@tonic-gate if (sigtable[sig].s_flag & SPAUSE)
321*7c478bd9Sstevel@tonic-gate longjmp(_pause, 1);
322*7c478bd9Sstevel@tonic-gate /*
323*7c478bd9Sstevel@tonic-gate * If signal is being held, mark its table entry
324*7c478bd9Sstevel@tonic-gate * so we can trigger it when signal is released.
325*7c478bd9Sstevel@tonic-gate * Then just return.
326*7c478bd9Sstevel@tonic-gate */
327*7c478bd9Sstevel@tonic-gate if (sigtable[sig].s_flag & SHELD) {
328*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag |= SDEFER;
329*7c478bd9Sstevel@tonic-gate signal(sig, _Sigtramp);
330*7c478bd9Sstevel@tonic-gate return;
331*7c478bd9Sstevel@tonic-gate }
332*7c478bd9Sstevel@tonic-gate /*
333*7c478bd9Sstevel@tonic-gate * If the signal is being ignored, just return.
334*7c478bd9Sstevel@tonic-gate * This would make SIGCONT more normal, but of course
335*7c478bd9Sstevel@tonic-gate * any system with SIGCONT also has the new signal pkg, so...
336*7c478bd9Sstevel@tonic-gate */
337*7c478bd9Sstevel@tonic-gate if (sigtable[sig].s_func == SIG_IGN)
338*7c478bd9Sstevel@tonic-gate return;
339*7c478bd9Sstevel@tonic-gate /*
340*7c478bd9Sstevel@tonic-gate * If the signal is SIG_DFL, then we probably got here
341*7c478bd9Sstevel@tonic-gate * by holding the signal, having it happen, then releasing
342*7c478bd9Sstevel@tonic-gate * the signal.
343*7c478bd9Sstevel@tonic-gate */
344*7c478bd9Sstevel@tonic-gate if (sigtable[sig].s_func == SIG_DFL) {
345*7c478bd9Sstevel@tonic-gate signal(sig, SIG_DFL);
346*7c478bd9Sstevel@tonic-gate kill(getpid(), sig);
347*7c478bd9Sstevel@tonic-gate /* Will we get back here? */
348*7c478bd9Sstevel@tonic-gate return;
349*7c478bd9Sstevel@tonic-gate }
350*7c478bd9Sstevel@tonic-gate /*
351*7c478bd9Sstevel@tonic-gate * Looks like we should just cause the signal...
352*7c478bd9Sstevel@tonic-gate * We hold the signal for the duration of the user's
353*7c478bd9Sstevel@tonic-gate * code with the signal re-enabled. If the signal
354*7c478bd9Sstevel@tonic-gate * happens again while in user code, we will recursively
355*7c478bd9Sstevel@tonic-gate * trap here and mark that we had another occurance
356*7c478bd9Sstevel@tonic-gate * and return to the user's trap code. When we return
357*7c478bd9Sstevel@tonic-gate * from there, we can cause the signal again.
358*7c478bd9Sstevel@tonic-gate */
359*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag &= ~SDEFER;
360*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag |= SHELD;
361*7c478bd9Sstevel@tonic-gate signal(sig, _Sigtramp);
362*7c478bd9Sstevel@tonic-gate (*sigtable[sig].s_func)(sig);
363*7c478bd9Sstevel@tonic-gate /*
364*7c478bd9Sstevel@tonic-gate * If the signal re-occurred while in the user's routine,
365*7c478bd9Sstevel@tonic-gate * just go try it again...
366*7c478bd9Sstevel@tonic-gate */
367*7c478bd9Sstevel@tonic-gate sigtable[sig].s_flag &= ~SHELD;
368*7c478bd9Sstevel@tonic-gate if (sigtable[sig].s_flag & SDEFER)
369*7c478bd9Sstevel@tonic-gate goto top;
370*7c478bd9Sstevel@tonic-gate }
371*7c478bd9Sstevel@tonic-gate #endif
372