tc.sig.h revision 167465
1181834Sroberto/* $Header: /p/tcsh/cvsroot/tcsh/tc.sig.h,v 3.32 2006/03/11 15:32:00 mitr Exp $ */ 2181834Sroberto/* 3181834Sroberto * tc.sig.h: Signal handling 4181834Sroberto * 5181834Sroberto */ 6181834Sroberto/*- 7181834Sroberto * Copyright (c) 1980, 1991 The Regents of the University of California. 8181834Sroberto * All rights reserved. 9181834Sroberto * 10181834Sroberto * Redistribution and use in source and binary forms, with or without 11181834Sroberto * modification, are permitted provided that the following conditions 12181834Sroberto * are met: 13181834Sroberto * 1. Redistributions of source code must retain the above copyright 14285612Sdelphij * notice, this list of conditions and the following disclaimer. 15285612Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 16285612Sdelphij * notice, this list of conditions and the following disclaimer in the 17181834Sroberto * documentation and/or other materials provided with the distribution. 18181834Sroberto * 3. Neither the name of the University nor the names of its contributors 19181834Sroberto * may be used to endorse or promote products derived from this software 20181834Sroberto * without specific prior written permission. 21181834Sroberto * 22181834Sroberto * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23181834Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24181834Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25181834Sroberto * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26181834Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27181834Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28181834Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29181834Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30181834Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31181834Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32181834Sroberto * SUCH DAMAGE. 33181834Sroberto */ 34181834Sroberto#ifndef _h_tc_sig 35181834Sroberto#define _h_tc_sig 36181834Sroberto 37181834Sroberto#if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT_NATIVE) 38181834Sroberto# include <signal.h> 39181834Sroberto# ifndef SIGCHLD 40181834Sroberto# define SIGCHLD SIGCLD 41181834Sroberto# endif /* SIGCHLD */ 42181834Sroberto#else /* SYSVREL == 0 */ 43181834Sroberto# include <sys/signal.h> 44181834Sroberto#endif /* SYSVREL > 0 */ 45181834Sroberto 46181834Sroberto#if defined(__APPLE__) || defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(VFORK)) 47181834Sroberto# define SAVESIGVEC 48181834Sroberto#endif /* SUNOS4 || DGUX || hp800 || SVR4 & VFORK */ 49181834Sroberto 50181834Sroberto#if SYSVREL > 0 51181834Sroberto# ifdef BSDJOBS 52181834Sroberto/* here I assume that systems that have bsdjobs implement the 53181834Sroberto * the setpgrp call correctly. Otherwise defining this would 54181834Sroberto * work, but it would kill the world, because all the setpgrp 55181834Sroberto * code is the the part defined when BSDJOBS are defined 56181834Sroberto * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b) 57181834Sroberto * cause process a might be already dead and getpgrp would fail 58181834Sroberto */ 59181834Sroberto# define killpg(a, b) kill(-(a), (b)) 60181834Sroberto# else 61285612Sdelphij/* this is the poor man's version of killpg()! Just kill the 62 * current process and don't worry about the rest. Someday 63 * I hope I get to fix that. 64 */ 65# define killpg(a, b) kill((a), (b)) 66# endif /* BSDJOBS */ 67#endif /* SYSVREL > 0 */ 68 69#ifdef _MINIX 70# include <signal.h> 71# define killpg(a, b) kill((a), (b)) 72# ifdef _MINIX_VMD 73# define signal(a, b) signal((a), (a) == SIGCHLD ? SIG_IGN : (b)) 74# endif /* _MINIX_VMD */ 75#endif /* _MINIX */ 76 77#ifdef _VMS_POSIX 78# define killpg(a, b) kill(-(a), (b)) 79#endif /* atp _VMS_POSIX */ 80 81#ifdef aiws 82# undef killpg 83# define killpg(a, b) kill(-getpgrp(a), b) 84#endif /* aiws */ 85 86#if !defined(NSIG) && defined(SIGMAX) 87# define NSIG (SIGMAX+1) 88#endif /* !NSIG && SIGMAX */ 89#if !defined(NSIG) && defined(_SIG_MAX) 90# define NSIG (_SIG_MAX+1) 91#endif /* !NSIG && _SIG_MAX */ 92#if !defined(NSIG) && defined(_NSIG) 93# define NSIG _NSIG 94#endif /* !NSIG && _NSIG */ 95#if !defined(NSIG) 96#define NSIG (sizeof(sigset_t) * 8) 97#endif /* !NSIG */ 98#if !defined(MAXSIG) && defined(NSIG) 99# define MAXSIG NSIG 100#endif /* !MAXSIG && NSIG */ 101 102/* 103 * We choose a define for the window signal if it exists.. 104 */ 105#ifdef SIGWINCH 106# define SIG_WINDOW SIGWINCH 107#else 108# ifdef SIGWINDOW 109# define SIG_WINDOW SIGWINDOW 110# endif /* SIGWINDOW */ 111#endif /* SIGWINCH */ 112 113#ifdef SAVESIGVEC 114# define NSIGSAVED 7 115 /* 116 * These are not inline for speed. gcc -traditional -O on the sparc ignores 117 * the fact that vfork() corrupts the registers. Calling a routine is not 118 * nice, since it can make the compiler put some things that we want saved 119 * into registers - christos 120 */ 121# define savesigvec(sv, sm) \ 122 do { \ 123 sigset_t m__; \ 124 \ 125 sigaction(SIGINT, NULL, &(sv)[0]); \ 126 sigaction(SIGQUIT, NULL, &(sv)[1]); \ 127 sigaction(SIGTSTP, NULL, &(sv)[2]); \ 128 sigaction(SIGTTIN, NULL, &(sv)[3]); \ 129 sigaction(SIGTTOU, NULL, &(sv)[4]); \ 130 sigaction(SIGTERM, NULL, &(sv)[5]); \ 131 sigaction(SIGHUP, NULL, &(sv)[6]); \ 132 sigemptyset(&m__); \ 133 sigaddset(&m__, SIGINT); \ 134 sigaddset(&m__, SIGQUIT); \ 135 sigaddset(&m__, SIGTSTP); \ 136 sigaddset(&m__, SIGTTIN); \ 137 sigaddset(&m__, SIGTTOU); \ 138 sigaddset(&m__, SIGTERM); \ 139 sigaddset(&m__, SIGHUP); \ 140 sigprocmask(SIG_BLOCK, &m__, &sm); \ 141 } while (0) 142 143# define restoresigvec(sv, sm) \ 144 do { \ 145 sigaction(SIGINT, &(sv)[0], NULL); \ 146 sigaction(SIGQUIT, &(sv)[1], NULL); \ 147 sigaction(SIGTSTP, &(sv)[2], NULL); \ 148 sigaction(SIGTTIN, &(sv)[3], NULL); \ 149 sigaction(SIGTTOU, &(sv)[4], NULL); \ 150 sigaction(SIGTERM, &(sv)[5], NULL); \ 151 sigaction(SIGHUP, &(sv)[6], NULL); \ 152 sigprocmask(SIG_SETMASK, &sm, NULL); \ 153 } while (0) 154# endif /* SAVESIGVEC */ 155 156extern int alrmcatch_disabled; 157extern int pchild_disabled; 158extern int phup_disabled; 159extern int pintr_disabled; 160 161extern void sigset_interrupting(int, void (*) (int)); 162extern void handle_pending_signals(void); 163 164extern void queue_alrmcatch(int); 165extern void queue_pchild(int); 166extern void queue_phup(int); 167extern void queue_pintr(int); 168 169extern void disabled_cleanup(void *); 170extern void pintr_disabled_restore(void *); 171extern void pintr_push_enable(int *); 172 173#endif /* _h_tc_sig */ 174