1 /* $Header: /src/pub/tcsh/tc.sig.h,v 3.26 2002/07/12 13:16:19 christos Exp $ */
3 * tc.sig.h: Signal handling
7 * Copyright (c) 1980, 1991 The Regents of the University of California.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT_NATIVE)
40 # define SIGCHLD SIGCLD
42 #else /* SYSVREL == 0 */
43 # include <sys/signal.h>
44 #endif /* SYSVREL > 0 */
46 #if defined(__APPLE__) || defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(POSIXSIGS) && defined(VFORK))
48 #endif /* SUNOS4 || DGUX || hp800 || SVR4 & POSIXSIGS & VFORK */
50 #if (SYSVREL > 0 && SYSVREL < 3 && !defined(BSDSIGS)) || defined(_MINIX) || defined(COHERENT)
52 * If we have unreliable signals...
55 #endif /* SYSVREL > 0 && SYSVREL < 3 && !BSDSIGS || _MINIX || COHERENT */
59 * sigvec is not the same everywhere
61 # if defined(_SEQUENT_) || (defined(_POSIX_SOURCE) && !defined(hpux))
63 # define mysigvec(a, b, c) sigaction(a, b, c)
64 typedef struct sigaction sigvec_t
;
65 /* eliminate compiler warnings since these are defined in signal.h */
68 # define sv_handler sa_handler
69 # define sv_flags sa_flags
70 # endif /* _SEQUENT || (_POSIX_SOURCE && !hpux) */
74 # define mysigvec(a, b, c) sigvector(a, b, c)
75 typedef struct sigvec sigvec_t
;
81 # define mysigvec(a, b, c) sigaction(a, b, c)
82 typedef struct sigaction sigvec_t
;
85 # define sv_handler sa_handler
86 # define sv_flags sa_flags
88 # define mysigvec(a, b, c) sigvec(a, b, c)
89 typedef struct sigvec sigvec_t
;
90 # endif /* POSIXSIGS */
91 # endif /* HAVE_SIGVEC */
98 /* here I assume that systems that have bsdjobs implement the
99 * the setpgrp call correctly. Otherwise defining this would
100 * work, but it would kill the world, because all the setpgrp
101 * code is the the part defined when BSDJOBS are defined
102 * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b)
103 * cause process a might be already dead and getpgrp would fail
105 # define killpg(a, b) kill(-(a), (b))
107 /* this is the poor man's version of killpg()! Just kill the
108 * current process and don't worry about the rest. Someday
109 * I hope I get to fix that.
111 # define killpg(a, b) kill((a), (b))
112 # endif /* BSDJOBS */
113 #endif /* SYSVREL > 0 */
117 # define killpg(a, b) kill((a), (b))
119 # define signal(a, b) signal((a), (a) == SIGCHLD ? SIG_IGN : (b))
120 # endif /* _MINIX_VMD */
124 # define killpg(a, b) kill(-(a), (b))
125 #endif /* atp _VMS_POSIX */
127 #if !defined(NSIG) && defined(SIGMAX)
128 # define NSIG (SIGMAX+1)
129 #endif /* !NSIG && SIGMAX */
130 #if !defined(NSIG) && defined(_SIG_MAX)
131 # define NSIG (_SIG_MAX+1)
132 #endif /* !NSIG && _SIG_MAX */
133 #if !defined(NSIG) && defined(_NSIG)
135 #endif /* !NSIG && _NSIG */
136 #if !defined(MAXSIG) && defined(NSIG)
138 #endif /* !MAXSIG && NSIG */
142 * For 4.2bsd signals.
146 # endif /* sigmask */
147 # define sigmask(s) (1 << ((s)-1))
149 # define sigpause(a) (void) bsd_sigpause(a)
152 # endif /* WINNT_NATIVE */
153 # define signal(a, b) bsd_signal(a, b)
154 # endif /* POSIXSIGS */
156 # define sighold(s) sigblock(sigmask(s))
157 # define sigignore(s) signal(s, SIG_IGN)
158 # define sigset(s, a) signal(s, a)
159 # endif /* !_SEQUENT_ */
161 # define sigrelse(a) sigsetmask(sigblock(0) & ~sigmask(a))
163 # define killpg(a, b) kill(-getpgrp(a), b)
170 * We choose a define for the window signal if it exists..
173 # define SIG_WINDOW SIGWINCH
176 # define SIG_WINDOW SIGWINDOW
177 # endif /* SIGWINDOW */
178 #endif /* SIGWINCH */
182 /* Does not seem to work right... Christos */
186 # define SYNCHMASK (sigmask(SIGCHLD)|sigmask(SIGSYNCH))
188 # define SYNCHMASK (sigmask(SIGCHLD))
190 extern sigret_t
synch_handler();
196 * These are not inline for speed. gcc -traditional -O on the sparc ignores
197 * the fact that vfork() corrupts the registers. Calling a routine is not
198 * nice, since it can make the compiler put some things that we want saved
199 * into registers - christos
201 # define savesigvec(sv) \
202 ((void) mysigvec(SIGINT, (sigvec_t *) 0, &(sv)[0]), \
203 (void) mysigvec(SIGQUIT, (sigvec_t *) 0, &(sv)[1]), \
204 (void) mysigvec(SIGTSTP, (sigvec_t *) 0, &(sv)[2]), \
205 (void) mysigvec(SIGTTIN, (sigvec_t *) 0, &(sv)[3]), \
206 (void) mysigvec(SIGTTOU, (sigvec_t *) 0, &(sv)[4]), \
207 (void) mysigvec(SIGTERM, (sigvec_t *) 0, &(sv)[5]), \
208 (void) mysigvec(SIGHUP, (sigvec_t *) 0, &(sv)[6]), \
209 sigblock(sigmask(SIGINT) | sigmask(SIGQUIT) | \
210 sigmask(SIGTSTP) | sigmask(SIGTTIN) | \
211 sigmask(SIGTTOU) | sigmask(SIGTERM) | \
214 # define restoresigvec(sv, sm) \
215 (void) ((void) mysigvec(SIGINT, &(sv)[0], (sigvec_t *) 0), \
216 (void) mysigvec(SIGQUIT, &(sv)[1], (sigvec_t *) 0), \
217 (void) mysigvec(SIGTSTP, &(sv)[2], (sigvec_t *) 0), \
218 (void) mysigvec(SIGTTIN, &(sv)[3], (sigvec_t *) 0), \
219 (void) mysigvec(SIGTTOU, &(sv)[4], (sigvec_t *) 0), \
220 (void) mysigvec(SIGTERM, &(sv)[5], (sigvec_t *) 0), \
221 (void) mysigvec(SIGHUP, &(sv)[6], (sigvec_t *) 0), \
222 (void) sigsetmask(sm))
223 # endif /* SAVESIGVEC */
225 #endif /* _h_tc_sig */