tc.sig.h revision 69408
169408Sache/* $Header: /src/pub/tcsh/tc.sig.h,v 3.22 2000/11/11 23:03:39 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.
1859243Sobrien * 3. All advertising materials mentioning features or use of this software
1959243Sobrien *    must display the following acknowledgement:
2059243Sobrien *	This product includes software developed by the University of
2159243Sobrien *	California, Berkeley and its contributors.
2259243Sobrien * 4. Neither the name of the University nor the names of its contributors
2359243Sobrien *    may be used to endorse or promote products derived from this software
2459243Sobrien *    without specific prior written permission.
2559243Sobrien *
2659243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2759243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2859243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2959243Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3059243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3159243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3259243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3359243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3459243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3559243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3659243Sobrien * SUCH DAMAGE.
3759243Sobrien */
3859243Sobrien#ifndef _h_tc_sig
3959243Sobrien#define _h_tc_sig
4059243Sobrien
4169408Sache#if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT_NATIVE)
4259243Sobrien# include <signal.h>
4359243Sobrien# ifndef SIGCHLD
4459243Sobrien#  define SIGCHLD SIGCLD
4559243Sobrien# endif /* SIGCHLD */
4659243Sobrien#else /* SYSVREL == 0 */
4759243Sobrien# include <sys/signal.h>
4859243Sobrien#endif /* SYSVREL > 0 */
4959243Sobrien
5059243Sobrien#if defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(POSIXSIGS) && defined(VFORK))
5159243Sobrien# define SAVESIGVEC
5259243Sobrien#endif /* SUNOS4 || DGUX || hp800 || SVR4 & POSIXSIGS & VFORK */
5359243Sobrien
5459243Sobrien#if (SYSVREL > 0 && SYSVREL < 3 && !defined(BSDSIGS)) || defined(_MINIX) || defined(COHERENT)
5559243Sobrien/*
5659243Sobrien * If we have unreliable signals...
5759243Sobrien */
5859243Sobrien# define UNRELSIGS
5959243Sobrien#endif /* SYSVREL > 0 && SYSVREL < 3 && !BSDSIGS || _MINIX || COHERENT */
6059243Sobrien
6159243Sobrien#ifdef BSDSIGS
6259243Sobrien/*
6359243Sobrien * sigvec is not the same everywhere
6459243Sobrien */
6559243Sobrien# if defined(_SEQUENT_) || (defined(_POSIX_SOURCE) && !defined(hpux))
6659243Sobrien#  define HAVE_SIGVEC
6759243Sobrien#  define mysigvec(a, b, c)	sigaction(a, b, c)
6859243Sobrientypedef struct sigaction sigvec_t;
6959243Sobrien#  if defined(convex) || defined(__convex__)
7059243Sobrien     /* eliminate compiler warnings since these are defined in signal.h  */
7159243Sobrien#    undef sv_handler
7259243Sobrien#    undef sv_flags
7359243Sobrien#  endif
7459243Sobrien#  define sv_handler sa_handler
7559243Sobrien#  define sv_flags sa_flags
7659243Sobrien# endif /* _SEQUENT || (_POSIX_SOURCE && !hpux) */
7759243Sobrien
7859243Sobrien# ifdef hpux
7959243Sobrien#  define HAVE_SIGVEC
8059243Sobrien#  define mysigvec(a, b, c)	sigvector(a, b, c)
8159243Sobrientypedef struct sigvec sigvec_t;
8259243Sobrien#  define NEEDsignal
8359243Sobrien# endif /* hpux */
8459243Sobrien
8559243Sobrien# ifndef HAVE_SIGVEC
8659243Sobrien#  ifdef POSIXSIGS
8759243Sobrien#  define mysigvec(a, b, c)	sigaction(a, b, c)
8859243Sobrientypedef struct sigaction sigvec_t;
8959243Sobrien#   define sv_handler sa_handler
9059243Sobrien#   define sv_flags sa_flags
9159243Sobrien#  else /* BSDSIGS */
9269408Sache#   define mysigvec(a, b, c)	sigvec(a, b, c)
9359243Sobrientypedef struct sigvec sigvec_t;
9459243Sobrien#  endif /* POSIXSIGS */
9559243Sobrien# endif /* HAVE_SIGVEC */
9659243Sobrien
9759243Sobrien# undef HAVE_SIGVEC
9859243Sobrien#endif /* BSDSIGS */
9959243Sobrien
10059243Sobrien#if SYSVREL > 0
10159243Sobrien# ifdef BSDJOBS
10259243Sobrien/* here I assume that systems that have bsdjobs implement the
10359243Sobrien * the setpgrp call correctly. Otherwise defining this would
10459243Sobrien * work, but it would kill the world, because all the setpgrp
10559243Sobrien * code is the the part defined when BSDJOBS are defined
10659243Sobrien * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b)
10759243Sobrien * cause process a might be already dead and getpgrp would fail
10859243Sobrien */
10959243Sobrien#  define killpg(a, b) kill(-(a), (b))
11059243Sobrien# else
11159243Sobrien/* this is the poor man's version of killpg()! Just kill the
11259243Sobrien * current process and don't worry about the rest. Someday
11359243Sobrien * I hope I get to fix that.
11459243Sobrien */
11559243Sobrien#  define killpg(a, b) kill((a), (b))
11659243Sobrien# endif /* BSDJOBS */
11759243Sobrien#endif /* SYSVREL > 0 */
11859243Sobrien
11959243Sobrien#ifdef _MINIX
12059243Sobrien# include <signal.h>
12169408Sache# define killpg(a, b) kill((a), (b))
12269408Sache# ifdef _MINIX_VMD
12369408Sache#  define signal(a, b) signal((a), (a) == SIGCHLD ? SIG_IGN : (b))
12469408Sache# endif /* _MINIX_VMD */
12559243Sobrien#endif /* _MINIX */
12659243Sobrien
12759243Sobrien#ifdef _VMS_POSIX
12859243Sobrien# define killpg(a, b) kill(-(a), (b))
12959243Sobrien#endif /* atp _VMS_POSIX */
13059243Sobrien
13159243Sobrien#if !defined(NSIG) && defined(SIGMAX)
13259243Sobrien# define NSIG (SIGMAX+1)
13359243Sobrien#endif /* !NSIG && SIGMAX */
13459243Sobrien#if !defined(NSIG) && defined(_SIG_MAX)
13559243Sobrien# define NSIG (_SIG_MAX+1)
13659243Sobrien#endif /* !NSIG && _SIG_MAX */
13759243Sobrien#if !defined(NSIG) && defined(_NSIG)
13859243Sobrien# define NSIG _NSIG
13959243Sobrien#endif /* !NSIG && _NSIG */
14059243Sobrien#if !defined(MAXSIG) && defined(NSIG)
14159243Sobrien# define MAXSIG NSIG
14259243Sobrien#endif /* !MAXSIG && NSIG */
14359243Sobrien
14459243Sobrien#ifdef BSDSIGS
14559243Sobrien/*
14659243Sobrien * For 4.2bsd signals.
14759243Sobrien */
14859243Sobrien# ifdef sigmask
14959243Sobrien#  undef sigmask
15059243Sobrien# endif /* sigmask */
15159243Sobrien# define	sigmask(s)	(1 << ((s)-1))
15259243Sobrien# ifdef POSIXSIGS
15359243Sobrien#  define 	sigpause(a)	(void) bsd_sigpause(a)
15469408Sache#  ifdef WINNT_NATIVE
15559243Sobrien#   undef signal
15669408Sache#  endif /* WINNT_NATIVE */
15759243Sobrien#  define 	signal(a, b)	bsd_signal(a, b)
15859243Sobrien# endif /* POSIXSIGS */
15959243Sobrien# ifndef _SEQUENT_
16059243Sobrien#  define	sighold(s)	sigblock(sigmask(s))
16159243Sobrien#  define	sigignore(s)	signal(s, SIG_IGN)
16259243Sobrien#  define 	sigset(s, a)	signal(s, a)
16359243Sobrien# endif /* !_SEQUENT_ */
16459243Sobrien# ifdef aiws
16559243Sobrien#  define 	sigrelse(a)	sigsetmask(sigblock(0) & ~sigmask(a))
16659243Sobrien#  undef	killpg
16759243Sobrien#  define 	killpg(a, b)	kill(-getpgrp(a), b)
16859243Sobrien#  define	NEEDsignal
16959243Sobrien# endif /* aiws */
17059243Sobrien#endif /* BSDSIGS */
17159243Sobrien
17259243Sobrien
17359243Sobrien/*
17459243Sobrien * We choose a define for the window signal if it exists..
17559243Sobrien */
17659243Sobrien#ifdef SIGWINCH
17759243Sobrien# define SIG_WINDOW SIGWINCH
17859243Sobrien#else
17959243Sobrien# ifdef SIGWINDOW
18059243Sobrien#  define SIG_WINDOW SIGWINDOW
18159243Sobrien# endif /* SIGWINDOW */
18259243Sobrien#endif /* SIGWINCH */
18359243Sobrien
18459243Sobrien#ifdef convex
18559243Sobrien# ifdef notdef
18659243Sobrien/* Does not seem to work right... Christos */
18759243Sobrien#  define SIGSYNCH       0
18859243Sobrien# endif
18959243Sobrien# ifdef SIGSYNCH
19059243Sobrien#  define SYNCHMASK 	(sigmask(SIGCHLD)|sigmask(SIGSYNCH))
19159243Sobrien# else
19259243Sobrien#  define SYNCHMASK 	(sigmask(SIGCHLD))
19359243Sobrien# endif
19459243Sobrienextern sigret_t synch_handler();
19559243Sobrien#endif /* convex */
19659243Sobrien
19759243Sobrien#ifdef SAVESIGVEC
19859243Sobrien# define NSIGSAVED 7
19959243Sobrien /*
20059243Sobrien  * These are not inline for speed. gcc -traditional -O on the sparc ignores
20159243Sobrien  * the fact that vfork() corrupts the registers. Calling a routine is not
20259243Sobrien  * nice, since it can make the compiler put some things that we want saved
20359243Sobrien  * into registers 				- christos
20459243Sobrien  */
20559243Sobrien# define savesigvec(sv)						\
20659243Sobrien   ((void) mysigvec(SIGINT,  (sigvec_t *) 0, &(sv)[0]),		\
20759243Sobrien    (void) mysigvec(SIGQUIT, (sigvec_t *) 0, &(sv)[1]),		\
20859243Sobrien    (void) mysigvec(SIGTSTP, (sigvec_t *) 0, &(sv)[2]),		\
20959243Sobrien    (void) mysigvec(SIGTTIN, (sigvec_t *) 0, &(sv)[3]),		\
21059243Sobrien    (void) mysigvec(SIGTTOU, (sigvec_t *) 0, &(sv)[4]),		\
21159243Sobrien    (void) mysigvec(SIGTERM, (sigvec_t *) 0, &(sv)[5]),		\
21259243Sobrien    (void) mysigvec(SIGHUP,  (sigvec_t *) 0, &(sv)[6]),		\
21359243Sobrien    sigblock(sigmask(SIGINT) | sigmask(SIGQUIT) | 		\
21459243Sobrien	    sigmask(SIGTSTP) | sigmask(SIGTTIN) | 		\
21559243Sobrien	    sigmask(SIGTTOU) | sigmask(SIGTERM) |		\
21659243Sobrien	    sigmask(SIGHUP)))
21759243Sobrien
21859243Sobrien# define restoresigvec(sv, sm)					\
21959243Sobrien    (void) ((void) mysigvec(SIGINT,  &(sv)[0], (sigvec_t *) 0),	\
22059243Sobrien	    (void) mysigvec(SIGQUIT, &(sv)[1], (sigvec_t *) 0),	\
22159243Sobrien	    (void) mysigvec(SIGTSTP, &(sv)[2], (sigvec_t *) 0),	\
22259243Sobrien	    (void) mysigvec(SIGTTIN, &(sv)[3], (sigvec_t *) 0),	\
22359243Sobrien	    (void) mysigvec(SIGTTOU, &(sv)[4], (sigvec_t *) 0),	\
22459243Sobrien	    (void) mysigvec(SIGTERM, &(sv)[5], (sigvec_t *) 0),	\
22559243Sobrien	    (void) mysigvec(SIGHUP,  &(sv)[6], (sigvec_t *) 0),	\
22659243Sobrien	    (void) sigsetmask(sm))
22759243Sobrien# endif /* SAVESIGVEC */
22859243Sobrien
22959243Sobrien#endif /* _h_tc_sig */
230