tc.sig.h revision 195609
1/* $Header: /p/tcsh/cvsroot/tcsh/tc.sig.h,v 3.33 2007/07/05 14:13:06 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) || defined(__QNXNTO__) 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(VFORK)) 47# define SAVESIGVEC 48#endif /* SUNOS4 || DGUX || hp800 || SVR4 & VFORK */ 49 50#if SYSVREL > 0 51# ifdef BSDJOBS 52/* here I assume that systems that have bsdjobs implement the 53 * the setpgrp call correctly. Otherwise defining this would 54 * work, but it would kill the world, because all the setpgrp 55 * code is the the part defined when BSDJOBS are defined 56 * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b) 57 * cause process a might be already dead and getpgrp would fail 58 */ 59# define killpg(a, b) kill(-(a), (b)) 60# else 61/* 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