1 /* $Header: /src/pub/tcsh/tc.sig.h,v 3.26 2002/07/12 13:16:19 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(MAXSIG) && defined(NSIG) 137 # define MAXSIG NSIG 138 #endif /* !MAXSIG && NSIG */ 139 140 #ifdef BSDSIGS 141 /* 142 * For 4.2bsd signals. 143 */ 144 # ifdef sigmask 145 # undef sigmask 146 # endif /* sigmask */ 147 # define sigmask(s) (1 << ((s)-1)) 148 # ifdef POSIXSIGS 149 # define sigpause(a) (void) bsd_sigpause(a) 150 # ifdef WINNT_NATIVE 151 # undef signal 152 # endif /* WINNT_NATIVE */ 153 # define signal(a, b) bsd_signal(a, b) 154 # endif /* POSIXSIGS */ 155 # ifndef _SEQUENT_ 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_ */ 160 # ifdef aiws 161 # define sigrelse(a) sigsetmask(sigblock(0) & ~sigmask(a)) 162 # undef killpg 163 # define killpg(a, b) kill(-getpgrp(a), b) 164 # define NEEDsignal 165 # endif /* aiws */ 166 #endif /* BSDSIGS */ 167 168 169 /* 170 * We choose a define for the window signal if it exists.. 171 */ 172 #ifdef SIGWINCH 173 # define SIG_WINDOW SIGWINCH 174 #else 175 # ifdef SIGWINDOW 176 # define SIG_WINDOW SIGWINDOW 177 # endif /* SIGWINDOW */ 178 #endif /* SIGWINCH */ 179 180 #ifdef convex 181 # ifdef notdef 182 /* Does not seem to work right... Christos */ 183 # define SIGSYNCH 0 184 # endif 185 # ifdef SIGSYNCH 186 # define SYNCHMASK (sigmask(SIGCHLD)|sigmask(SIGSYNCH)) 187 # else 188 # define SYNCHMASK (sigmask(SIGCHLD)) 189 # endif 190 extern sigret_t synch_handler(); 191 #endif /* convex */ 192 193 #ifdef SAVESIGVEC 194 # define NSIGSAVED 7 195 /* 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 200 */ 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) | \ 212 sigmask(SIGHUP))) 213 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 */ 224 225 #endif /* _h_tc_sig */ 226