1231990Smp/* $Header: /p/tcsh/cvsroot/tcsh/tc.sig.h,v 3.34 2010/11/29 15:28:58 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 37195609Smp#if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT_NATIVE) || defined(__QNXNTO__) 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 46167465Smp#if defined(__APPLE__) || defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(VFORK)) 4759243Sobrien# define SAVESIGVEC 48167465Smp#endif /* SUNOS4 || DGUX || hp800 || SVR4 & VFORK */ 4959243Sobrien 5059243Sobrien#if SYSVREL > 0 5159243Sobrien# ifdef BSDJOBS 5259243Sobrien/* here I assume that systems that have bsdjobs implement the 5359243Sobrien * the setpgrp call correctly. Otherwise defining this would 5459243Sobrien * work, but it would kill the world, because all the setpgrp 5559243Sobrien * code is the the part defined when BSDJOBS are defined 5659243Sobrien * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b) 5759243Sobrien * cause process a might be already dead and getpgrp would fail 5859243Sobrien */ 5959243Sobrien# define killpg(a, b) kill(-(a), (b)) 6059243Sobrien# else 6159243Sobrien/* this is the poor man's version of killpg()! Just kill the 6259243Sobrien * current process and don't worry about the rest. Someday 6359243Sobrien * I hope I get to fix that. 6459243Sobrien */ 6559243Sobrien# define killpg(a, b) kill((a), (b)) 6659243Sobrien# endif /* BSDJOBS */ 6759243Sobrien#endif /* SYSVREL > 0 */ 6859243Sobrien 6959243Sobrien#ifdef _MINIX 7059243Sobrien# include <signal.h> 7169408Sache# define killpg(a, b) kill((a), (b)) 7269408Sache# ifdef _MINIX_VMD 7369408Sache# define signal(a, b) signal((a), (a) == SIGCHLD ? SIG_IGN : (b)) 7469408Sache# endif /* _MINIX_VMD */ 7559243Sobrien#endif /* _MINIX */ 7659243Sobrien 7759243Sobrien#ifdef _VMS_POSIX 7859243Sobrien# define killpg(a, b) kill(-(a), (b)) 7959243Sobrien#endif /* atp _VMS_POSIX */ 8059243Sobrien 81167465Smp#ifdef aiws 82167465Smp# undef killpg 83167465Smp# define killpg(a, b) kill(-getpgrp(a), b) 84167465Smp#endif /* aiws */ 85167465Smp 8659243Sobrien#if !defined(NSIG) && defined(SIGMAX) 8759243Sobrien# define NSIG (SIGMAX+1) 8859243Sobrien#endif /* !NSIG && SIGMAX */ 8959243Sobrien#if !defined(NSIG) && defined(_SIG_MAX) 9059243Sobrien# define NSIG (_SIG_MAX+1) 9159243Sobrien#endif /* !NSIG && _SIG_MAX */ 9259243Sobrien#if !defined(NSIG) && defined(_NSIG) 9359243Sobrien# define NSIG _NSIG 9459243Sobrien#endif /* !NSIG && _NSIG */ 95145479Smp#if !defined(NSIG) 96145479Smp#define NSIG (sizeof(sigset_t) * 8) 97145479Smp#endif /* !NSIG */ 9859243Sobrien#if !defined(MAXSIG) && defined(NSIG) 9959243Sobrien# define MAXSIG NSIG 10059243Sobrien#endif /* !MAXSIG && NSIG */ 10159243Sobrien 10259243Sobrien/* 10359243Sobrien * We choose a define for the window signal if it exists.. 10459243Sobrien */ 10559243Sobrien#ifdef SIGWINCH 10659243Sobrien# define SIG_WINDOW SIGWINCH 10759243Sobrien#else 10859243Sobrien# ifdef SIGWINDOW 10959243Sobrien# define SIG_WINDOW SIGWINDOW 11059243Sobrien# endif /* SIGWINDOW */ 11159243Sobrien#endif /* SIGWINCH */ 11259243Sobrien 11359243Sobrien#ifdef SAVESIGVEC 11459243Sobrien# define NSIGSAVED 7 11559243Sobrien /* 11659243Sobrien * These are not inline for speed. gcc -traditional -O on the sparc ignores 11759243Sobrien * the fact that vfork() corrupts the registers. Calling a routine is not 11859243Sobrien * nice, since it can make the compiler put some things that we want saved 11959243Sobrien * into registers - christos 12059243Sobrien */ 121167465Smp# define savesigvec(sv, sm) \ 122167465Smp do { \ 123167465Smp sigset_t m__; \ 124167465Smp \ 125167465Smp sigaction(SIGINT, NULL, &(sv)[0]); \ 126167465Smp sigaction(SIGQUIT, NULL, &(sv)[1]); \ 127167465Smp sigaction(SIGTSTP, NULL, &(sv)[2]); \ 128167465Smp sigaction(SIGTTIN, NULL, &(sv)[3]); \ 129167465Smp sigaction(SIGTTOU, NULL, &(sv)[4]); \ 130167465Smp sigaction(SIGTERM, NULL, &(sv)[5]); \ 131167465Smp sigaction(SIGHUP, NULL, &(sv)[6]); \ 132167465Smp sigemptyset(&m__); \ 133167465Smp sigaddset(&m__, SIGINT); \ 134167465Smp sigaddset(&m__, SIGQUIT); \ 135167465Smp sigaddset(&m__, SIGTSTP); \ 136167465Smp sigaddset(&m__, SIGTTIN); \ 137167465Smp sigaddset(&m__, SIGTTOU); \ 138167465Smp sigaddset(&m__, SIGTERM); \ 139167465Smp sigaddset(&m__, SIGHUP); \ 140167465Smp sigprocmask(SIG_BLOCK, &m__, &sm); \ 141167465Smp } while (0) 14259243Sobrien 143167465Smp# define restoresigvec(sv, sm) \ 144167465Smp do { \ 145167465Smp sigaction(SIGINT, &(sv)[0], NULL); \ 146167465Smp sigaction(SIGQUIT, &(sv)[1], NULL); \ 147167465Smp sigaction(SIGTSTP, &(sv)[2], NULL); \ 148167465Smp sigaction(SIGTTIN, &(sv)[3], NULL); \ 149167465Smp sigaction(SIGTTOU, &(sv)[4], NULL); \ 150167465Smp sigaction(SIGTERM, &(sv)[5], NULL); \ 151167465Smp sigaction(SIGHUP, &(sv)[6], NULL); \ 152167465Smp sigprocmask(SIG_SETMASK, &sm, NULL); \ 153167465Smp } while (0) 15459243Sobrien# endif /* SAVESIGVEC */ 15559243Sobrien 156167465Smpextern int alrmcatch_disabled; 157167465Smpextern int pchild_disabled; 158167465Smpextern int phup_disabled; 159167465Smpextern int pintr_disabled; 160167465Smp 161167465Smpextern void sigset_interrupting(int, void (*) (int)); 162231990Smpextern int handle_pending_signals(void); 163167465Smp 164167465Smpextern void queue_alrmcatch(int); 165167465Smpextern void queue_pchild(int); 166167465Smpextern void queue_phup(int); 167167465Smpextern void queue_pintr(int); 168167465Smp 169167465Smpextern void disabled_cleanup(void *); 170167465Smpextern void pintr_disabled_restore(void *); 171167465Smpextern void pintr_push_enable(int *); 172167465Smp 17359243Sobrien#endif /* _h_tc_sig */ 174