xref: /freebsd/contrib/tcsh/tc.sig.h (revision d056fa046c6a91b90cd98165face0e42a33a5173)
1 /* $Header: /src/pub/tcsh/tc.sig.h,v 3.28 2005/01/18 20:24:51 christos Exp $ */
2 /*
3  * tc.sig.h: Signal handling
4  *
5  */
6 /*-
7  * Copyright (c) 1980, 1991 The Regents of the University of California.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
21  *
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
32  * SUCH DAMAGE.
33  */
34 #ifndef _h_tc_sig
35 #define _h_tc_sig
36 
37 #if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT_NATIVE)
38 # include <signal.h>
39 # ifndef SIGCHLD
40 #  define SIGCHLD SIGCLD
41 # endif /* SIGCHLD */
42 #else /* SYSVREL == 0 */
43 # include <sys/signal.h>
44 #endif /* SYSVREL > 0 */
45 
46 #if defined(__APPLE__) || defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(POSIXSIGS) && defined(VFORK))
47 # define SAVESIGVEC
48 #endif /* SUNOS4 || DGUX || hp800 || SVR4 & POSIXSIGS & VFORK */
49 
50 #if (SYSVREL > 0 && SYSVREL < 3 && !defined(BSDSIGS)) || defined(_MINIX) || defined(COHERENT)
51 /*
52  * If we have unreliable signals...
53  */
54 # define UNRELSIGS
55 #endif /* SYSVREL > 0 && SYSVREL < 3 && !BSDSIGS || _MINIX || COHERENT */
56 
57 #ifdef BSDSIGS
58 /*
59  * sigvec is not the same everywhere
60  */
61 # if defined(_SEQUENT_) || (defined(_POSIX_SOURCE) && !defined(hpux))
62 #  define HAVE_SIGVEC
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  */
66 #  undef sv_handler
67 #  undef sv_flags
68 #  define sv_handler sa_handler
69 #  define sv_flags sa_flags
70 # endif /* _SEQUENT || (_POSIX_SOURCE && !hpux) */
71 
72 # ifdef hpux
73 #  define HAVE_SIGVEC
74 #  define mysigvec(a, b, c)	sigvector(a, b, c)
75 typedef struct sigvec sigvec_t;
76 #  define NEEDsignal
77 # endif /* hpux */
78 
79 # ifndef HAVE_SIGVEC
80 #  ifdef POSIXSIGS
81 #  define mysigvec(a, b, c)	sigaction(a, b, c)
82 typedef struct sigaction sigvec_t;
83 #   undef sv_handler
84 #   undef sv_flags
85 #   define sv_handler sa_handler
86 #   define sv_flags sa_flags
87 #  else /* BSDSIGS */
88 #   define mysigvec(a, b, c)	sigvec(a, b, c)
89 typedef struct sigvec sigvec_t;
90 #  endif /* POSIXSIGS */
91 # endif /* HAVE_SIGVEC */
92 
93 # undef HAVE_SIGVEC
94 #endif /* BSDSIGS */
95 
96 #if SYSVREL > 0
97 # ifdef BSDJOBS
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
104  */
105 #  define killpg(a, b) kill(-(a), (b))
106 # else
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.
110  */
111 #  define killpg(a, b) kill((a), (b))
112 # endif /* BSDJOBS */
113 #endif /* SYSVREL > 0 */
114 
115 #ifdef _MINIX
116 # include <signal.h>
117 # define killpg(a, b) kill((a), (b))
118 # ifdef _MINIX_VMD
119 #  define signal(a, b) signal((a), (a) == SIGCHLD ? SIG_IGN : (b))
120 # endif /* _MINIX_VMD */
121 #endif /* _MINIX */
122 
123 #ifdef _VMS_POSIX
124 # define killpg(a, b) kill(-(a), (b))
125 #endif /* atp _VMS_POSIX */
126 
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)
134 # define NSIG _NSIG
135 #endif /* !NSIG && _NSIG */
136 #if !defined(NSIG)
137 #define NSIG (sizeof(sigset_t) * 8)
138 #endif /* !NSIG */
139 #if !defined(MAXSIG) && defined(NSIG)
140 # define MAXSIG NSIG
141 #endif /* !MAXSIG && NSIG */
142 
143 #ifdef BSDSIGS
144 /*
145  * For 4.2bsd signals.
146  */
147 # ifdef sigmask
148 #  undef sigmask
149 # endif /* sigmask */
150 # define	sigmask(s)	(1 << ((s)-1))
151 # ifdef POSIXSIGS
152 #  define 	sigpause(a)	(void) bsd_sigpause(a)
153 #  ifdef WINNT_NATIVE
154 #   undef signal
155 #  endif /* WINNT_NATIVE */
156 #  define 	signal(a, b)	bsd_signal(a, b)
157 # endif /* POSIXSIGS */
158 # ifndef _SEQUENT_
159 #  define	sighold(s)	sigblock(sigmask(s))
160 #  define	sigignore(s)	signal(s, SIG_IGN)
161 #  define 	sigset(s, a)	signal(s, a)
162 # endif /* !_SEQUENT_ */
163 # ifdef aiws
164 #  define 	sigrelse(a)	sigsetmask(sigblock(0) & ~sigmask(a))
165 #  undef	killpg
166 #  define 	killpg(a, b)	kill(-getpgrp(a), b)
167 #  define	NEEDsignal
168 # endif /* aiws */
169 #endif /* BSDSIGS */
170 
171 
172 /*
173  * We choose a define for the window signal if it exists..
174  */
175 #ifdef SIGWINCH
176 # define SIG_WINDOW SIGWINCH
177 #else
178 # ifdef SIGWINDOW
179 #  define SIG_WINDOW SIGWINDOW
180 # endif /* SIGWINDOW */
181 #endif /* SIGWINCH */
182 
183 #ifdef convex
184 # ifdef notdef
185 /* Does not seem to work right... Christos */
186 #  define SIGSYNCH       0
187 # endif
188 # ifdef SIGSYNCH
189 #  define SYNCHMASK 	(sigmask(SIGCHLD)|sigmask(SIGSYNCH))
190 # else
191 #  define SYNCHMASK 	(sigmask(SIGCHLD))
192 # endif
193 extern RETSIGTYPE synch_handler();
194 #endif /* convex */
195 
196 #ifdef SAVESIGVEC
197 # define NSIGSAVED 7
198  /*
199   * These are not inline for speed. gcc -traditional -O on the sparc ignores
200   * the fact that vfork() corrupts the registers. Calling a routine is not
201   * nice, since it can make the compiler put some things that we want saved
202   * into registers 				- christos
203   */
204 # define savesigvec(sv)						\
205    ((void) mysigvec(SIGINT,  (sigvec_t *) 0, &(sv)[0]),		\
206     (void) mysigvec(SIGQUIT, (sigvec_t *) 0, &(sv)[1]),		\
207     (void) mysigvec(SIGTSTP, (sigvec_t *) 0, &(sv)[2]),		\
208     (void) mysigvec(SIGTTIN, (sigvec_t *) 0, &(sv)[3]),		\
209     (void) mysigvec(SIGTTOU, (sigvec_t *) 0, &(sv)[4]),		\
210     (void) mysigvec(SIGTERM, (sigvec_t *) 0, &(sv)[5]),		\
211     (void) mysigvec(SIGHUP,  (sigvec_t *) 0, &(sv)[6]),		\
212     sigblock(sigmask(SIGINT) | sigmask(SIGQUIT) | 		\
213 	    sigmask(SIGTSTP) | sigmask(SIGTTIN) | 		\
214 	    sigmask(SIGTTOU) | sigmask(SIGTERM) |		\
215 	    sigmask(SIGHUP)))
216 
217 # define restoresigvec(sv, sm)					\
218     (void) ((void) mysigvec(SIGINT,  &(sv)[0], (sigvec_t *) 0),	\
219 	    (void) mysigvec(SIGQUIT, &(sv)[1], (sigvec_t *) 0),	\
220 	    (void) mysigvec(SIGTSTP, &(sv)[2], (sigvec_t *) 0),	\
221 	    (void) mysigvec(SIGTTIN, &(sv)[3], (sigvec_t *) 0),	\
222 	    (void) mysigvec(SIGTTOU, &(sv)[4], (sigvec_t *) 0),	\
223 	    (void) mysigvec(SIGTERM, &(sv)[5], (sigvec_t *) 0),	\
224 	    (void) mysigvec(SIGHUP,  &(sv)[6], (sigvec_t *) 0),	\
225 	    (void) sigsetmask(sm))
226 # endif /* SAVESIGVEC */
227 
228 #endif /* _h_tc_sig */
229