tc.sig.h revision 100616
1100616Smp/* $Header: /src/pub/tcsh/tc.sig.h,v 3.26 2002/07/12 13:16:19 christos Exp $ */ 259243Sobrien/* 359243Sobrien * tc.sig.h: Signal handling 459243Sobrien * 559243Sobrien */ 659243Sobrien/*- 759243Sobrien * Copyright (c) 1980, 1991 The Regents of the University of California. 859243Sobrien * All rights reserved. 959243Sobrien * 1059243Sobrien * Redistribution and use in source and binary forms, with or without 1159243Sobrien * modification, are permitted provided that the following conditions 1259243Sobrien * are met: 1359243Sobrien * 1. Redistributions of source code must retain the above copyright 1459243Sobrien * notice, this list of conditions and the following disclaimer. 1559243Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1659243Sobrien * notice, this list of conditions and the following disclaimer in the 1759243Sobrien * documentation and/or other materials provided with the distribution. 18100616Smp * 3. Neither the name of the University nor the names of its contributors 1959243Sobrien * may be used to endorse or promote products derived from this software 2059243Sobrien * without specific prior written permission. 2159243Sobrien * 2259243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2359243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2459243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2559243Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2659243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2759243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2859243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2959243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3059243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3159243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3259243Sobrien * SUCH DAMAGE. 3359243Sobrien */ 3459243Sobrien#ifndef _h_tc_sig 3559243Sobrien#define _h_tc_sig 3659243Sobrien 3769408Sache#if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT_NATIVE) 3859243Sobrien# include <signal.h> 3959243Sobrien# ifndef SIGCHLD 4059243Sobrien# define SIGCHLD SIGCLD 4159243Sobrien# endif /* SIGCHLD */ 4259243Sobrien#else /* SYSVREL == 0 */ 4359243Sobrien# include <sys/signal.h> 4459243Sobrien#endif /* SYSVREL > 0 */ 4559243Sobrien 46100616Smp#if defined(__APPLE__) || defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(POSIXSIGS) && defined(VFORK)) 4759243Sobrien# define SAVESIGVEC 4859243Sobrien#endif /* SUNOS4 || DGUX || hp800 || SVR4 & POSIXSIGS & VFORK */ 4959243Sobrien 5059243Sobrien#if (SYSVREL > 0 && SYSVREL < 3 && !defined(BSDSIGS)) || defined(_MINIX) || defined(COHERENT) 5159243Sobrien/* 5259243Sobrien * If we have unreliable signals... 5359243Sobrien */ 5459243Sobrien# define UNRELSIGS 5559243Sobrien#endif /* SYSVREL > 0 && SYSVREL < 3 && !BSDSIGS || _MINIX || COHERENT */ 5659243Sobrien 5759243Sobrien#ifdef BSDSIGS 5859243Sobrien/* 5959243Sobrien * sigvec is not the same everywhere 6059243Sobrien */ 6159243Sobrien# if defined(_SEQUENT_) || (defined(_POSIX_SOURCE) && !defined(hpux)) 6259243Sobrien# define HAVE_SIGVEC 6359243Sobrien# define mysigvec(a, b, c) sigaction(a, b, c) 6459243Sobrientypedef struct sigaction sigvec_t; 65100616Smp/* eliminate compiler warnings since these are defined in signal.h */ 66100616Smp# undef sv_handler 67100616Smp# undef sv_flags 6859243Sobrien# define sv_handler sa_handler 6959243Sobrien# define sv_flags sa_flags 7059243Sobrien# endif /* _SEQUENT || (_POSIX_SOURCE && !hpux) */ 7159243Sobrien 7259243Sobrien# ifdef hpux 7359243Sobrien# define HAVE_SIGVEC 7459243Sobrien# define mysigvec(a, b, c) sigvector(a, b, c) 7559243Sobrientypedef struct sigvec sigvec_t; 7659243Sobrien# define NEEDsignal 7759243Sobrien# endif /* hpux */ 7859243Sobrien 7959243Sobrien# ifndef HAVE_SIGVEC 8059243Sobrien# ifdef POSIXSIGS 8159243Sobrien# define mysigvec(a, b, c) sigaction(a, b, c) 8259243Sobrientypedef struct sigaction sigvec_t; 83100616Smp# undef sv_handler 84100616Smp# undef sv_flags 8559243Sobrien# define sv_handler sa_handler 8659243Sobrien# define sv_flags sa_flags 8759243Sobrien# else /* BSDSIGS */ 8869408Sache# define mysigvec(a, b, c) sigvec(a, b, c) 8959243Sobrientypedef struct sigvec sigvec_t; 9059243Sobrien# endif /* POSIXSIGS */ 9159243Sobrien# endif /* HAVE_SIGVEC */ 9259243Sobrien 9359243Sobrien# undef HAVE_SIGVEC 9459243Sobrien#endif /* BSDSIGS */ 9559243Sobrien 9659243Sobrien#if SYSVREL > 0 9759243Sobrien# ifdef BSDJOBS 9859243Sobrien/* here I assume that systems that have bsdjobs implement the 9959243Sobrien * the setpgrp call correctly. Otherwise defining this would 10059243Sobrien * work, but it would kill the world, because all the setpgrp 10159243Sobrien * code is the the part defined when BSDJOBS are defined 10259243Sobrien * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b) 10359243Sobrien * cause process a might be already dead and getpgrp would fail 10459243Sobrien */ 10559243Sobrien# define killpg(a, b) kill(-(a), (b)) 10659243Sobrien# else 10759243Sobrien/* this is the poor man's version of killpg()! Just kill the 10859243Sobrien * current process and don't worry about the rest. Someday 10959243Sobrien * I hope I get to fix that. 11059243Sobrien */ 11159243Sobrien# define killpg(a, b) kill((a), (b)) 11259243Sobrien# endif /* BSDJOBS */ 11359243Sobrien#endif /* SYSVREL > 0 */ 11459243Sobrien 11559243Sobrien#ifdef _MINIX 11659243Sobrien# include <signal.h> 11769408Sache# define killpg(a, b) kill((a), (b)) 11869408Sache# ifdef _MINIX_VMD 11969408Sache# define signal(a, b) signal((a), (a) == SIGCHLD ? SIG_IGN : (b)) 12069408Sache# endif /* _MINIX_VMD */ 12159243Sobrien#endif /* _MINIX */ 12259243Sobrien 12359243Sobrien#ifdef _VMS_POSIX 12459243Sobrien# define killpg(a, b) kill(-(a), (b)) 12559243Sobrien#endif /* atp _VMS_POSIX */ 12659243Sobrien 12759243Sobrien#if !defined(NSIG) && defined(SIGMAX) 12859243Sobrien# define NSIG (SIGMAX+1) 12959243Sobrien#endif /* !NSIG && SIGMAX */ 13059243Sobrien#if !defined(NSIG) && defined(_SIG_MAX) 13159243Sobrien# define NSIG (_SIG_MAX+1) 13259243Sobrien#endif /* !NSIG && _SIG_MAX */ 13359243Sobrien#if !defined(NSIG) && defined(_NSIG) 13459243Sobrien# define NSIG _NSIG 13559243Sobrien#endif /* !NSIG && _NSIG */ 13659243Sobrien#if !defined(MAXSIG) && defined(NSIG) 13759243Sobrien# define MAXSIG NSIG 13859243Sobrien#endif /* !MAXSIG && NSIG */ 13959243Sobrien 14059243Sobrien#ifdef BSDSIGS 14159243Sobrien/* 14259243Sobrien * For 4.2bsd signals. 14359243Sobrien */ 14459243Sobrien# ifdef sigmask 14559243Sobrien# undef sigmask 14659243Sobrien# endif /* sigmask */ 14759243Sobrien# define sigmask(s) (1 << ((s)-1)) 14859243Sobrien# ifdef POSIXSIGS 14959243Sobrien# define sigpause(a) (void) bsd_sigpause(a) 15069408Sache# ifdef WINNT_NATIVE 15159243Sobrien# undef signal 15269408Sache# endif /* WINNT_NATIVE */ 15359243Sobrien# define signal(a, b) bsd_signal(a, b) 15459243Sobrien# endif /* POSIXSIGS */ 15559243Sobrien# ifndef _SEQUENT_ 15659243Sobrien# define sighold(s) sigblock(sigmask(s)) 15759243Sobrien# define sigignore(s) signal(s, SIG_IGN) 15859243Sobrien# define sigset(s, a) signal(s, a) 15959243Sobrien# endif /* !_SEQUENT_ */ 16059243Sobrien# ifdef aiws 16159243Sobrien# define sigrelse(a) sigsetmask(sigblock(0) & ~sigmask(a)) 16259243Sobrien# undef killpg 16359243Sobrien# define killpg(a, b) kill(-getpgrp(a), b) 16459243Sobrien# define NEEDsignal 16559243Sobrien# endif /* aiws */ 16659243Sobrien#endif /* BSDSIGS */ 16759243Sobrien 16859243Sobrien 16959243Sobrien/* 17059243Sobrien * We choose a define for the window signal if it exists.. 17159243Sobrien */ 17259243Sobrien#ifdef SIGWINCH 17359243Sobrien# define SIG_WINDOW SIGWINCH 17459243Sobrien#else 17559243Sobrien# ifdef SIGWINDOW 17659243Sobrien# define SIG_WINDOW SIGWINDOW 17759243Sobrien# endif /* SIGWINDOW */ 17859243Sobrien#endif /* SIGWINCH */ 17959243Sobrien 18059243Sobrien#ifdef convex 18159243Sobrien# ifdef notdef 18259243Sobrien/* Does not seem to work right... Christos */ 18359243Sobrien# define SIGSYNCH 0 18459243Sobrien# endif 18559243Sobrien# ifdef SIGSYNCH 18659243Sobrien# define SYNCHMASK (sigmask(SIGCHLD)|sigmask(SIGSYNCH)) 18759243Sobrien# else 18859243Sobrien# define SYNCHMASK (sigmask(SIGCHLD)) 18959243Sobrien# endif 19059243Sobrienextern sigret_t synch_handler(); 19159243Sobrien#endif /* convex */ 19259243Sobrien 19359243Sobrien#ifdef SAVESIGVEC 19459243Sobrien# define NSIGSAVED 7 19559243Sobrien /* 19659243Sobrien * These are not inline for speed. gcc -traditional -O on the sparc ignores 19759243Sobrien * the fact that vfork() corrupts the registers. Calling a routine is not 19859243Sobrien * nice, since it can make the compiler put some things that we want saved 19959243Sobrien * into registers - christos 20059243Sobrien */ 20159243Sobrien# define savesigvec(sv) \ 20259243Sobrien ((void) mysigvec(SIGINT, (sigvec_t *) 0, &(sv)[0]), \ 20359243Sobrien (void) mysigvec(SIGQUIT, (sigvec_t *) 0, &(sv)[1]), \ 20459243Sobrien (void) mysigvec(SIGTSTP, (sigvec_t *) 0, &(sv)[2]), \ 20559243Sobrien (void) mysigvec(SIGTTIN, (sigvec_t *) 0, &(sv)[3]), \ 20659243Sobrien (void) mysigvec(SIGTTOU, (sigvec_t *) 0, &(sv)[4]), \ 20759243Sobrien (void) mysigvec(SIGTERM, (sigvec_t *) 0, &(sv)[5]), \ 20859243Sobrien (void) mysigvec(SIGHUP, (sigvec_t *) 0, &(sv)[6]), \ 20959243Sobrien sigblock(sigmask(SIGINT) | sigmask(SIGQUIT) | \ 21059243Sobrien sigmask(SIGTSTP) | sigmask(SIGTTIN) | \ 21159243Sobrien sigmask(SIGTTOU) | sigmask(SIGTERM) | \ 21259243Sobrien sigmask(SIGHUP))) 21359243Sobrien 21459243Sobrien# define restoresigvec(sv, sm) \ 21559243Sobrien (void) ((void) mysigvec(SIGINT, &(sv)[0], (sigvec_t *) 0), \ 21659243Sobrien (void) mysigvec(SIGQUIT, &(sv)[1], (sigvec_t *) 0), \ 21759243Sobrien (void) mysigvec(SIGTSTP, &(sv)[2], (sigvec_t *) 0), \ 21859243Sobrien (void) mysigvec(SIGTTIN, &(sv)[3], (sigvec_t *) 0), \ 21959243Sobrien (void) mysigvec(SIGTTOU, &(sv)[4], (sigvec_t *) 0), \ 22059243Sobrien (void) mysigvec(SIGTERM, &(sv)[5], (sigvec_t *) 0), \ 22159243Sobrien (void) mysigvec(SIGHUP, &(sv)[6], (sigvec_t *) 0), \ 22259243Sobrien (void) sigsetmask(sm)) 22359243Sobrien# endif /* SAVESIGVEC */ 22459243Sobrien 22559243Sobrien#endif /* _h_tc_sig */ 226