tc.sig.h revision 145479
1156956Sume/* $Header: /src/pub/tcsh/tc.sig.h,v 3.28 2005/01/18 20:24:51 christos Exp $ */
2156956Sume/*
3156956Sume * tc.sig.h: Signal handling
4156956Sume *
5156956Sume */
6156956Sume/*-
7156956Sume * Copyright (c) 1980, 1991 The Regents of the University of California.
8156956Sume * All rights reserved.
9156956Sume *
10156956Sume * Redistribution and use in source and binary forms, with or without
11156956Sume * modification, are permitted provided that the following conditions
12156956Sume * are met:
13156956Sume * 1. Redistributions of source code must retain the above copyright
14156956Sume *    notice, this list of conditions and the following disclaimer.
15156956Sume * 2. Redistributions in binary form must reproduce the above copyright
16156956Sume *    notice, this list of conditions and the following disclaimer in the
17156956Sume *    documentation and/or other materials provided with the distribution.
18156956Sume * 3. Neither the name of the University nor the names of its contributors
19156956Sume *    may be used to endorse or promote products derived from this software
20156956Sume *    without specific prior written permission.
21156956Sume *
22156956Sume * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23156956Sume * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24156956Sume * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25156956Sume * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26156956Sume * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27156956Sume * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28156956Sume * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29156956Sume * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30156956Sume * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31156956Sume * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32156956Sume * SUCH DAMAGE.
33156956Sume */
34156956Sume#ifndef _h_tc_sig
35156956Sume#define _h_tc_sig
36156956Sume
37156956Sume#if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT_NATIVE)
38156956Sume# include <signal.h>
39156956Sume# ifndef SIGCHLD
40156956Sume#  define SIGCHLD SIGCLD
41156956Sume# endif /* SIGCHLD */
42156956Sume#else /* SYSVREL == 0 */
43156956Sume# include <sys/signal.h>
44156956Sume#endif /* SYSVREL > 0 */
45156956Sume
46156956Sume#if defined(__APPLE__) || defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(POSIXSIGS) && defined(VFORK))
47156956Sume# define SAVESIGVEC
48156956Sume#endif /* SUNOS4 || DGUX || hp800 || SVR4 & POSIXSIGS & VFORK */
49156956Sume
50156956Sume#if (SYSVREL > 0 && SYSVREL < 3 && !defined(BSDSIGS)) || defined(_MINIX) || defined(COHERENT)
51156956Sume/*
52156956Sume * If we have unreliable signals...
53156956Sume */
54156956Sume# define UNRELSIGS
55156956Sume#endif /* SYSVREL > 0 && SYSVREL < 3 && !BSDSIGS || _MINIX || COHERENT */
56156956Sume
57156956Sume#ifdef BSDSIGS
58156956Sume/*
59156956Sume * sigvec is not the same everywhere
60156956Sume */
61156956Sume# if defined(_SEQUENT_) || (defined(_POSIX_SOURCE) && !defined(hpux))
62156956Sume#  define HAVE_SIGVEC
63156956Sume#  define mysigvec(a, b, c)	sigaction(a, b, c)
64158787Sumetypedef struct sigaction sigvec_t;
65158787Sume/* eliminate compiler warnings since these are defined in signal.h  */
66156956Sume#  undef sv_handler
67156956Sume#  undef sv_flags
68158787Sume#  define sv_handler sa_handler
69158787Sume#  define sv_flags sa_flags
70156956Sume# endif /* _SEQUENT || (_POSIX_SOURCE && !hpux) */
71156956Sume
72156956Sume# ifdef hpux
73156956Sume#  define HAVE_SIGVEC
74156956Sume#  define mysigvec(a, b, c)	sigvector(a, b, c)
75156956Sumetypedef struct sigvec sigvec_t;
76156956Sume#  define NEEDsignal
77156956Sume# endif /* hpux */
78156956Sume
79156956Sume# ifndef HAVE_SIGVEC
80156956Sume#  ifdef POSIXSIGS
81158787Sume#  define mysigvec(a, b, c)	sigaction(a, b, c)
82156956Sumetypedef struct sigaction sigvec_t;
83156956Sume#   undef sv_handler
84156956Sume#   undef sv_flags
85156956Sume#   define sv_handler sa_handler
86156956Sume#   define sv_flags sa_flags
87158787Sume#  else /* BSDSIGS */
88156956Sume#   define mysigvec(a, b, c)	sigvec(a, b, c)
89156956Sumetypedef struct sigvec sigvec_t;
90156956Sume#  endif /* POSIXSIGS */
91156956Sume# endif /* HAVE_SIGVEC */
92156956Sume
93156956Sume# undef HAVE_SIGVEC
94157282Sdeischen#endif /* BSDSIGS */
95156956Sume
96156956Sume#if SYSVREL > 0
97156956Sume# ifdef BSDJOBS
98156956Sume/* here I assume that systems that have bsdjobs implement the
99156956Sume * the setpgrp call correctly. Otherwise defining this would
100156956Sume * work, but it would kill the world, because all the setpgrp
101156956Sume * code is the the part defined when BSDJOBS are defined
102156956Sume * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b)
103156956Sume * cause process a might be already dead and getpgrp would fail
104156956Sume */
105156956Sume#  define killpg(a, b) kill(-(a), (b))
106156956Sume# else
107156956Sume/* this is the poor man's version of killpg()! Just kill the
108158787Sume * current process and don't worry about the rest. Someday
109156956Sume * 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
193extern 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