xref: /freebsd/contrib/tcsh/tc.sig.h (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
1 /*
2  * tc.sig.h: Signal handling
3  *
4  */
5 /*-
6  * Copyright (c) 1980, 1991 The Regents of the University of California.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 #ifndef _h_tc_sig
34 #define _h_tc_sig
35 
36 #if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT_NATIVE) || defined(__QNXNTO__)
37 # include <signal.h>
38 # ifndef SIGCHLD
39 #  define SIGCHLD SIGCLD
40 # endif /* SIGCHLD */
41 #else /* SYSVREL == 0 */
42 # include <sys/signal.h>
43 #endif /* SYSVREL > 0 */
44 
45 #if defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(VFORK))
46 # define SAVESIGVEC
47 #endif /* SUNOS4 || DGUX || hp800 || SVR4 & VFORK */
48 
49 #if SYSVREL > 0
50 # ifdef BSDJOBS
51 /* here I assume that systems that have bsdjobs implement the
52  * the setpgrp call correctly. Otherwise defining this would
53  * work, but it would kill the world, because all the setpgrp
54  * code is the the part defined when BSDJOBS are defined
55  * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b)
56  * cause process a might be already dead and getpgrp would fail
57  */
58 #  define killpg(a, b) kill(-(a), (b))
59 # else
60 /* this is the poor man's version of killpg()! Just kill the
61  * current process and don't worry about the rest. Someday
62  * I hope I get to fix that.
63  */
64 #  define killpg(a, b) kill((a), (b))
65 # endif /* BSDJOBS */
66 #endif /* SYSVREL > 0 */
67 
68 #ifdef _MINIX
69 # include <signal.h>
70 # define killpg(a, b) kill((a), (b))
71 # ifdef _MINIX_VMD
72 #  define signal(a, b) signal((a), (a) == SIGCHLD ? SIG_IGN : (b))
73 # endif /* _MINIX_VMD */
74 #endif /* _MINIX */
75 
76 #ifdef _VMS_POSIX
77 # define killpg(a, b) kill(-(a), (b))
78 #endif /* atp _VMS_POSIX */
79 
80 #ifdef aiws
81 # undef	killpg
82 # define 	killpg(a, b)	kill(-getpgrp(a), b)
83 #endif /* aiws */
84 
85 #if !defined(NSIG) && defined(SIGMAX)
86 # define NSIG (SIGMAX+1)
87 #endif /* !NSIG && SIGMAX */
88 #if !defined(NSIG) && defined(_SIG_MAX)
89 # define NSIG (_SIG_MAX+1)
90 #endif /* !NSIG && _SIG_MAX */
91 #if !defined(NSIG) && defined(_NSIG)
92 # define NSIG _NSIG
93 #endif /* !NSIG && _NSIG */
94 #if !defined(NSIG)
95 #define NSIG (sizeof(sigset_t) * 8)
96 #endif /* !NSIG */
97 #if !defined(MAXSIG) && defined(NSIG)
98 # define MAXSIG NSIG
99 #endif /* !MAXSIG && NSIG */
100 
101 /*
102  * We choose a define for the window signal if it exists..
103  */
104 #ifdef SIGWINCH
105 # define SIG_WINDOW SIGWINCH
106 #else
107 # ifdef SIGWINDOW
108 #  define SIG_WINDOW SIGWINDOW
109 # endif /* SIGWINDOW */
110 #endif /* SIGWINCH */
111 
112 #ifdef SAVESIGVEC
113 # define NSIGSAVED 7
114  /*
115   * These are not inline for speed. gcc -traditional -O on the sparc ignores
116   * the fact that vfork() corrupts the registers. Calling a routine is not
117   * nice, since it can make the compiler put some things that we want saved
118   * into registers 				- christos
119   */
120 # define savesigvec(sv, sm)			\
121     do {					\
122 	sigset_t m__;				\
123 						\
124 	sigaction(SIGINT,  NULL, &(sv)[0]);	\
125 	sigaction(SIGQUIT, NULL, &(sv)[1]);	\
126 	sigaction(SIGTSTP, NULL, &(sv)[2]);	\
127 	sigaction(SIGTTIN, NULL, &(sv)[3]);	\
128 	sigaction(SIGTTOU, NULL, &(sv)[4]);	\
129 	sigaction(SIGTERM, NULL, &(sv)[5]);	\
130 	sigaction(SIGHUP,  NULL, &(sv)[6]);	\
131 	sigemptyset(&m__);			\
132 	sigaddset(&m__, SIGINT);		\
133 	sigaddset(&m__, SIGQUIT);		\
134 	sigaddset(&m__, SIGTSTP);		\
135 	sigaddset(&m__, SIGTTIN);		\
136 	sigaddset(&m__, SIGTTOU);		\
137 	sigaddset(&m__, SIGTERM);		\
138 	sigaddset(&m__, SIGHUP);		\
139 	sigprocmask(SIG_BLOCK, &m__, &sm);	\
140     } while (0)
141 
142 # define restoresigvec(sv, sm)			\
143     do {					\
144 	sigaction(SIGINT,  &(sv)[0], NULL);	\
145 	sigaction(SIGQUIT, &(sv)[1], NULL);	\
146 	sigaction(SIGTSTP, &(sv)[2], NULL);	\
147 	sigaction(SIGTTIN, &(sv)[3], NULL);	\
148 	sigaction(SIGTTOU, &(sv)[4], NULL);	\
149 	sigaction(SIGTERM, &(sv)[5], NULL);	\
150 	sigaction(SIGHUP,  &(sv)[6], NULL);	\
151 	sigprocmask(SIG_SETMASK, &sm, NULL);	\
152     } while (0)
153 # endif /* SAVESIGVEC */
154 
155 extern int alrmcatch_disabled;
156 extern int pchild_disabled;
157 extern int phup_disabled;
158 extern int pintr_disabled;
159 
160 extern void sigset_interrupting(int, void (*) (int));
161 extern int handle_pending_signals(void);
162 
163 extern void queue_alrmcatch(int);
164 extern void queue_pchild(int);
165 extern void queue_phup(int);
166 extern void queue_pintr(int);
167 
168 extern void disabled_cleanup(void *);
169 extern void pintr_disabled_restore(void *);
170 extern void pintr_push_enable(int *);
171 
172 #endif /* _h_tc_sig */
173