tc.sig.h revision 59243
1173362Sbenjsc/* $Header: /src/pub/tcsh/tc.sig.h,v 3.20 1998/04/08 17:57:37 christos Exp $ */ 2173362Sbenjsc/* 3173362Sbenjsc * tc.sig.h: Signal handling 4173362Sbenjsc * 5173362Sbenjsc */ 6173362Sbenjsc/*- 7173362Sbenjsc * Copyright (c) 1980, 1991 The Regents of the University of California. 8173362Sbenjsc * All rights reserved. 9173362Sbenjsc * 10173362Sbenjsc * Redistribution and use in source and binary forms, with or without 11173362Sbenjsc * modification, are permitted provided that the following conditions 12173362Sbenjsc * are met: 13173362Sbenjsc * 1. Redistributions of source code must retain the above copyright 14173362Sbenjsc * notice, this list of conditions and the following disclaimer. 15173362Sbenjsc * 2. Redistributions in binary form must reproduce the above copyright 16173362Sbenjsc * notice, this list of conditions and the following disclaimer in the 17173362Sbenjsc * documentation and/or other materials provided with the distribution. 18173362Sbenjsc * 3. All advertising materials mentioning features or use of this software 19173362Sbenjsc * must display the following acknowledgement: 20173362Sbenjsc * This product includes software developed by the University of 21173362Sbenjsc * California, Berkeley and its contributors. 22173362Sbenjsc * 4. Neither the name of the University nor the names of its contributors 23173362Sbenjsc * may be used to endorse or promote products derived from this software 24173362Sbenjsc * without specific prior written permission. 25173362Sbenjsc * 26173362Sbenjsc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27173362Sbenjsc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28173362Sbenjsc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29173362Sbenjsc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30173362Sbenjsc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31173362Sbenjsc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32173362Sbenjsc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33173362Sbenjsc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34173362Sbenjsc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35173362Sbenjsc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36173362Sbenjsc * SUCH DAMAGE. 37173362Sbenjsc */ 38173362Sbenjsc#ifndef _h_tc_sig 39173362Sbenjsc#define _h_tc_sig 40173362Sbenjsc 41173362Sbenjsc#if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT) 42173362Sbenjsc# include <signal.h> 43173362Sbenjsc# ifndef SIGCHLD 44173362Sbenjsc# define SIGCHLD SIGCLD 45173362Sbenjsc# endif /* SIGCHLD */ 46173362Sbenjsc#else /* SYSVREL == 0 */ 47173362Sbenjsc# include <sys/signal.h> 48173362Sbenjsc#endif /* SYSVREL > 0 */ 49173362Sbenjsc 50173362Sbenjsc#if defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(POSIXSIGS) && defined(VFORK)) 51173362Sbenjsc# define SAVESIGVEC 52173362Sbenjsc#endif /* SUNOS4 || DGUX || hp800 || SVR4 & POSIXSIGS & VFORK */ 53173362Sbenjsc 54173362Sbenjsc#if (SYSVREL > 0 && SYSVREL < 3 && !defined(BSDSIGS)) || defined(_MINIX) || defined(COHERENT) 55173362Sbenjsc/* 56173362Sbenjsc * If we have unreliable signals... 57173362Sbenjsc */ 58173362Sbenjsc# define UNRELSIGS 59173362Sbenjsc#endif /* SYSVREL > 0 && SYSVREL < 3 && !BSDSIGS || _MINIX || COHERENT */ 60173362Sbenjsc 61173362Sbenjsc#ifdef BSDSIGS 62173362Sbenjsc/* 63173362Sbenjsc * sigvec is not the same everywhere 64173362Sbenjsc */ 65173362Sbenjsc# if defined(_SEQUENT_) || (defined(_POSIX_SOURCE) && !defined(hpux)) 66173362Sbenjsc# define HAVE_SIGVEC 67173362Sbenjsc# define mysigvec(a, b, c) sigaction(a, b, c) 68173362Sbenjsctypedef struct sigaction sigvec_t; 69173362Sbenjsc# if defined(convex) || defined(__convex__) 70173362Sbenjsc /* eliminate compiler warnings since these are defined in signal.h */ 71173362Sbenjsc# undef sv_handler 72173362Sbenjsc# undef sv_flags 73173362Sbenjsc# endif 74173362Sbenjsc# define sv_handler sa_handler 75173362Sbenjsc# define sv_flags sa_flags 76173362Sbenjsc# endif /* _SEQUENT || (_POSIX_SOURCE && !hpux) */ 77173362Sbenjsc 78173362Sbenjsc# ifdef hpux 79173362Sbenjsc# define HAVE_SIGVEC 80173362Sbenjsc# define mysigvec(a, b, c) sigvector(a, b, c) 81173362Sbenjsctypedef struct sigvec sigvec_t; 82173362Sbenjsc# define NEEDsignal 83173362Sbenjsc# endif /* hpux */ 84173362Sbenjsc 85173362Sbenjsc# ifndef HAVE_SIGVEC 86173362Sbenjsc# ifdef POSIXSIGS 87173362Sbenjsc# define mysigvec(a, b, c) sigaction(a, b, c) 88173362Sbenjsctypedef struct sigaction sigvec_t; 89173362Sbenjsc# define sv_handler sa_handler 90173362Sbenjsc# define sv_flags sa_flags 91173362Sbenjsc# else /* BSDSIGS */ 92173362Sbenjsc# define mysigvec(a, b, c) sigvec(a, b, c) 93173362Sbenjsctypedef struct sigvec sigvec_t; 94173362Sbenjsc# endif /* POSIXSIGS */ 95173362Sbenjsc# endif /* HAVE_SIGVEC */ 96173362Sbenjsc 97173362Sbenjsc# undef HAVE_SIGVEC 98173362Sbenjsc#endif /* BSDSIGS */ 99173362Sbenjsc 100173362Sbenjsc#if SYSVREL > 0 101173362Sbenjsc# ifdef BSDJOBS 102173362Sbenjsc/* here I assume that systems that have bsdjobs implement the 103173362Sbenjsc * the setpgrp call correctly. Otherwise defining this would 104173362Sbenjsc * work, but it would kill the world, because all the setpgrp 105173362Sbenjsc * code is the the part defined when BSDJOBS are defined 106173362Sbenjsc * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b) 107173362Sbenjsc * cause process a might be already dead and getpgrp would fail 108173362Sbenjsc */ 109173362Sbenjsc# define killpg(a, b) kill(-(a), (b)) 110173362Sbenjsc# else 111173362Sbenjsc/* this is the poor man's version of killpg()! Just kill the 112173362Sbenjsc * current process and don't worry about the rest. Someday 113173362Sbenjsc * I hope I get to fix that. 114173362Sbenjsc */ 115173362Sbenjsc# define killpg(a, b) kill((a), (b)) 116173362Sbenjsc# endif /* BSDJOBS */ 117173362Sbenjsc#endif /* SYSVREL > 0 */ 118173362Sbenjsc 119173362Sbenjsc#ifdef _MINIX 120173362Sbenjsc# include <signal.h> 121173362Sbenjsc# define killpg(a, b) kill((a), (b)) 122173362Sbenjsc#endif /* _MINIX */ 123173362Sbenjsc 124173362Sbenjsc#ifdef _VMS_POSIX 125173362Sbenjsc# define killpg(a, b) kill(-(a), (b)) 126173362Sbenjsc#endif /* atp _VMS_POSIX */ 127173362Sbenjsc 128173362Sbenjsc#if !defined(NSIG) && defined(SIGMAX) 129173362Sbenjsc# define NSIG (SIGMAX+1) 130173362Sbenjsc#endif /* !NSIG && SIGMAX */ 131173362Sbenjsc#if !defined(NSIG) && defined(_SIG_MAX) 132173362Sbenjsc# define NSIG (_SIG_MAX+1) 133173362Sbenjsc#endif /* !NSIG && _SIG_MAX */ 134173362Sbenjsc#if !defined(NSIG) && defined(_NSIG) 135173362Sbenjsc# define NSIG _NSIG 136173362Sbenjsc#endif /* !NSIG && _NSIG */ 137173362Sbenjsc#if !defined(MAXSIG) && defined(NSIG) 138173362Sbenjsc# define MAXSIG NSIG 139173362Sbenjsc#endif /* !MAXSIG && NSIG */ 140173362Sbenjsc 141173362Sbenjsc#ifdef BSDSIGS 142173362Sbenjsc/* 143173362Sbenjsc * For 4.2bsd signals. 144173362Sbenjsc */ 145173362Sbenjsc# ifdef sigmask 146173362Sbenjsc# undef sigmask 147173362Sbenjsc# endif /* sigmask */ 148173362Sbenjsc# define sigmask(s) (1 << ((s)-1)) 149173362Sbenjsc# ifdef POSIXSIGS 150173362Sbenjsc# define sigpause(a) (void) bsd_sigpause(a) 151173362Sbenjsc# ifdef WINNT 152173362Sbenjsc# undef signal 153173362Sbenjsc# endif /* WINNT */ 154173362Sbenjsc# define signal(a, b) bsd_signal(a, b) 155173362Sbenjsc# endif /* POSIXSIGS */ 156173362Sbenjsc# ifndef _SEQUENT_ 157173362Sbenjsc# define sighold(s) sigblock(sigmask(s)) 158173362Sbenjsc# define sigignore(s) signal(s, SIG_IGN) 159173362Sbenjsc# define sigset(s, a) signal(s, a) 160173362Sbenjsc# endif /* !_SEQUENT_ */ 161173362Sbenjsc# ifdef aiws 162173362Sbenjsc# define sigrelse(a) sigsetmask(sigblock(0) & ~sigmask(a)) 163173362Sbenjsc# undef killpg 164173362Sbenjsc# define killpg(a, b) kill(-getpgrp(a), b) 165173362Sbenjsc# define NEEDsignal 166173362Sbenjsc# endif /* aiws */ 167173362Sbenjsc#endif /* BSDSIGS */ 168173362Sbenjsc 169173362Sbenjsc 170173362Sbenjsc/* 171173362Sbenjsc * We choose a define for the window signal if it exists.. 172173362Sbenjsc */ 173173362Sbenjsc#ifdef SIGWINCH 174173362Sbenjsc# define SIG_WINDOW SIGWINCH 175173362Sbenjsc#else 176173362Sbenjsc# ifdef SIGWINDOW 177173362Sbenjsc# define SIG_WINDOW SIGWINDOW 178173362Sbenjsc# endif /* SIGWINDOW */ 179173362Sbenjsc#endif /* SIGWINCH */ 180173362Sbenjsc 181173362Sbenjsc#ifdef convex 182173362Sbenjsc# ifdef notdef 183173362Sbenjsc/* Does not seem to work right... Christos */ 184173362Sbenjsc# define SIGSYNCH 0 185173362Sbenjsc# endif 186173362Sbenjsc# ifdef SIGSYNCH 187173362Sbenjsc# define SYNCHMASK (sigmask(SIGCHLD)|sigmask(SIGSYNCH)) 188173362Sbenjsc# else 189173362Sbenjsc# define SYNCHMASK (sigmask(SIGCHLD)) 190173362Sbenjsc# endif 191173362Sbenjscextern sigret_t synch_handler(); 192173362Sbenjsc#endif /* convex */ 193173362Sbenjsc 194173362Sbenjsc#ifdef SAVESIGVEC 195173362Sbenjsc# define NSIGSAVED 7 196173362Sbenjsc /* 197173362Sbenjsc * These are not inline for speed. gcc -traditional -O on the sparc ignores 198173362Sbenjsc * the fact that vfork() corrupts the registers. Calling a routine is not 199173362Sbenjsc * nice, since it can make the compiler put some things that we want saved 200173362Sbenjsc * into registers - christos 201173362Sbenjsc */ 202173362Sbenjsc# define savesigvec(sv) \ 203173362Sbenjsc ((void) mysigvec(SIGINT, (sigvec_t *) 0, &(sv)[0]), \ 204173362Sbenjsc (void) mysigvec(SIGQUIT, (sigvec_t *) 0, &(sv)[1]), \ 205173362Sbenjsc (void) mysigvec(SIGTSTP, (sigvec_t *) 0, &(sv)[2]), \ 206173362Sbenjsc (void) mysigvec(SIGTTIN, (sigvec_t *) 0, &(sv)[3]), \ 207173362Sbenjsc (void) mysigvec(SIGTTOU, (sigvec_t *) 0, &(sv)[4]), \ 208173362Sbenjsc (void) mysigvec(SIGTERM, (sigvec_t *) 0, &(sv)[5]), \ 209173362Sbenjsc (void) mysigvec(SIGHUP, (sigvec_t *) 0, &(sv)[6]), \ 210173362Sbenjsc sigblock(sigmask(SIGINT) | sigmask(SIGQUIT) | \ 211173362Sbenjsc sigmask(SIGTSTP) | sigmask(SIGTTIN) | \ 212173362Sbenjsc sigmask(SIGTTOU) | sigmask(SIGTERM) | \ 213173362Sbenjsc sigmask(SIGHUP))) 214173362Sbenjsc 215173362Sbenjsc# define restoresigvec(sv, sm) \ 216173362Sbenjsc (void) ((void) mysigvec(SIGINT, &(sv)[0], (sigvec_t *) 0), \ 217173362Sbenjsc (void) mysigvec(SIGQUIT, &(sv)[1], (sigvec_t *) 0), \ 218173362Sbenjsc (void) mysigvec(SIGTSTP, &(sv)[2], (sigvec_t *) 0), \ 219173362Sbenjsc (void) mysigvec(SIGTTIN, &(sv)[3], (sigvec_t *) 0), \ 220173362Sbenjsc (void) mysigvec(SIGTTOU, &(sv)[4], (sigvec_t *) 0), \ 221173362Sbenjsc (void) mysigvec(SIGTERM, &(sv)[5], (sigvec_t *) 0), \ 222173362Sbenjsc (void) mysigvec(SIGHUP, &(sv)[6], (sigvec_t *) 0), \ 223173362Sbenjsc (void) sigsetmask(sm)) 224173362Sbenjsc# endif /* SAVESIGVEC */ 225173362Sbenjsc 226173362Sbenjsc#endif /* _h_tc_sig */ 227173362Sbenjsc