159243Sobrien/* 259243Sobrien * tc.sig.h: Signal handling 359243Sobrien * 459243Sobrien */ 559243Sobrien/*- 659243Sobrien * Copyright (c) 1980, 1991 The Regents of the University of California. 759243Sobrien * All rights reserved. 859243Sobrien * 959243Sobrien * Redistribution and use in source and binary forms, with or without 1059243Sobrien * modification, are permitted provided that the following conditions 1159243Sobrien * are met: 1259243Sobrien * 1. Redistributions of source code must retain the above copyright 1359243Sobrien * notice, this list of conditions and the following disclaimer. 1459243Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1559243Sobrien * notice, this list of conditions and the following disclaimer in the 1659243Sobrien * documentation and/or other materials provided with the distribution. 17100616Smp * 3. Neither the name of the University nor the names of its contributors 1859243Sobrien * may be used to endorse or promote products derived from this software 1959243Sobrien * without specific prior written permission. 2059243Sobrien * 2159243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2259243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2359243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2459243Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2559243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2659243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2759243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2859243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2959243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3059243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3159243Sobrien * SUCH DAMAGE. 3259243Sobrien */ 3359243Sobrien#ifndef _h_tc_sig 3459243Sobrien#define _h_tc_sig 3559243Sobrien 36195609Smp#if (SYSVREL > 0) || defined(BSD4_4) || defined(_MINIX) || defined(DGUX) || defined(WINNT_NATIVE) || defined(__QNXNTO__) 3759243Sobrien# include <signal.h> 3859243Sobrien# ifndef SIGCHLD 3959243Sobrien# define SIGCHLD SIGCLD 4059243Sobrien# endif /* SIGCHLD */ 4159243Sobrien#else /* SYSVREL == 0 */ 4259243Sobrien# include <sys/signal.h> 4359243Sobrien#endif /* SYSVREL > 0 */ 4459243Sobrien 45354195Sbrooks#if defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(VFORK)) 4659243Sobrien# define SAVESIGVEC 47167465Smp#endif /* SUNOS4 || DGUX || hp800 || SVR4 & VFORK */ 4859243Sobrien 4959243Sobrien#if SYSVREL > 0 5059243Sobrien# ifdef BSDJOBS 5159243Sobrien/* here I assume that systems that have bsdjobs implement the 5259243Sobrien * the setpgrp call correctly. Otherwise defining this would 5359243Sobrien * work, but it would kill the world, because all the setpgrp 5459243Sobrien * code is the the part defined when BSDJOBS are defined 5559243Sobrien * NOTE: we don't want killpg(a, b) == kill(-getpgrp(a), b) 5659243Sobrien * cause process a might be already dead and getpgrp would fail 5759243Sobrien */ 5859243Sobrien# define killpg(a, b) kill(-(a), (b)) 5959243Sobrien# else 6059243Sobrien/* this is the poor man's version of killpg()! Just kill the 6159243Sobrien * current process and don't worry about the rest. Someday 6259243Sobrien * I hope I get to fix that. 6359243Sobrien */ 6459243Sobrien# define killpg(a, b) kill((a), (b)) 6559243Sobrien# endif /* BSDJOBS */ 6659243Sobrien#endif /* SYSVREL > 0 */ 6759243Sobrien 6859243Sobrien#ifdef _MINIX 6959243Sobrien# include <signal.h> 7069408Sache# define killpg(a, b) kill((a), (b)) 7169408Sache# ifdef _MINIX_VMD 7269408Sache# define signal(a, b) signal((a), (a) == SIGCHLD ? SIG_IGN : (b)) 7369408Sache# endif /* _MINIX_VMD */ 7459243Sobrien#endif /* _MINIX */ 7559243Sobrien 7659243Sobrien#ifdef _VMS_POSIX 7759243Sobrien# define killpg(a, b) kill(-(a), (b)) 7859243Sobrien#endif /* atp _VMS_POSIX */ 7959243Sobrien 80167465Smp#ifdef aiws 81167465Smp# undef killpg 82167465Smp# define killpg(a, b) kill(-getpgrp(a), b) 83167465Smp#endif /* aiws */ 84167465Smp 8559243Sobrien#if !defined(NSIG) && defined(SIGMAX) 8659243Sobrien# define NSIG (SIGMAX+1) 8759243Sobrien#endif /* !NSIG && SIGMAX */ 8859243Sobrien#if !defined(NSIG) && defined(_SIG_MAX) 8959243Sobrien# define NSIG (_SIG_MAX+1) 9059243Sobrien#endif /* !NSIG && _SIG_MAX */ 9159243Sobrien#if !defined(NSIG) && defined(_NSIG) 9259243Sobrien# define NSIG _NSIG 9359243Sobrien#endif /* !NSIG && _NSIG */ 94145479Smp#if !defined(NSIG) 95145479Smp#define NSIG (sizeof(sigset_t) * 8) 96145479Smp#endif /* !NSIG */ 9759243Sobrien#if !defined(MAXSIG) && defined(NSIG) 9859243Sobrien# define MAXSIG NSIG 9959243Sobrien#endif /* !MAXSIG && NSIG */ 10059243Sobrien 10159243Sobrien/* 10259243Sobrien * We choose a define for the window signal if it exists.. 10359243Sobrien */ 10459243Sobrien#ifdef SIGWINCH 10559243Sobrien# define SIG_WINDOW SIGWINCH 10659243Sobrien#else 10759243Sobrien# ifdef SIGWINDOW 10859243Sobrien# define SIG_WINDOW SIGWINDOW 10959243Sobrien# endif /* SIGWINDOW */ 11059243Sobrien#endif /* SIGWINCH */ 11159243Sobrien 11259243Sobrien#ifdef SAVESIGVEC 11359243Sobrien# define NSIGSAVED 7 11459243Sobrien /* 11559243Sobrien * These are not inline for speed. gcc -traditional -O on the sparc ignores 11659243Sobrien * the fact that vfork() corrupts the registers. Calling a routine is not 11759243Sobrien * nice, since it can make the compiler put some things that we want saved 11859243Sobrien * into registers - christos 11959243Sobrien */ 120167465Smp# define savesigvec(sv, sm) \ 121167465Smp do { \ 122167465Smp sigset_t m__; \ 123167465Smp \ 124167465Smp sigaction(SIGINT, NULL, &(sv)[0]); \ 125167465Smp sigaction(SIGQUIT, NULL, &(sv)[1]); \ 126167465Smp sigaction(SIGTSTP, NULL, &(sv)[2]); \ 127167465Smp sigaction(SIGTTIN, NULL, &(sv)[3]); \ 128167465Smp sigaction(SIGTTOU, NULL, &(sv)[4]); \ 129167465Smp sigaction(SIGTERM, NULL, &(sv)[5]); \ 130167465Smp sigaction(SIGHUP, NULL, &(sv)[6]); \ 131167465Smp sigemptyset(&m__); \ 132167465Smp sigaddset(&m__, SIGINT); \ 133167465Smp sigaddset(&m__, SIGQUIT); \ 134167465Smp sigaddset(&m__, SIGTSTP); \ 135167465Smp sigaddset(&m__, SIGTTIN); \ 136167465Smp sigaddset(&m__, SIGTTOU); \ 137167465Smp sigaddset(&m__, SIGTERM); \ 138167465Smp sigaddset(&m__, SIGHUP); \ 139167465Smp sigprocmask(SIG_BLOCK, &m__, &sm); \ 140167465Smp } while (0) 14159243Sobrien 142167465Smp# define restoresigvec(sv, sm) \ 143167465Smp do { \ 144167465Smp sigaction(SIGINT, &(sv)[0], NULL); \ 145167465Smp sigaction(SIGQUIT, &(sv)[1], NULL); \ 146167465Smp sigaction(SIGTSTP, &(sv)[2], NULL); \ 147167465Smp sigaction(SIGTTIN, &(sv)[3], NULL); \ 148167465Smp sigaction(SIGTTOU, &(sv)[4], NULL); \ 149167465Smp sigaction(SIGTERM, &(sv)[5], NULL); \ 150167465Smp sigaction(SIGHUP, &(sv)[6], NULL); \ 151167465Smp sigprocmask(SIG_SETMASK, &sm, NULL); \ 152167465Smp } while (0) 15359243Sobrien# endif /* SAVESIGVEC */ 15459243Sobrien 155167465Smpextern int alrmcatch_disabled; 156167465Smpextern int pchild_disabled; 157167465Smpextern int phup_disabled; 158167465Smpextern int pintr_disabled; 159167465Smp 160167465Smpextern void sigset_interrupting(int, void (*) (int)); 161231990Smpextern int handle_pending_signals(void); 162167465Smp 163167465Smpextern void queue_alrmcatch(int); 164167465Smpextern void queue_pchild(int); 165167465Smpextern void queue_phup(int); 166167465Smpextern void queue_pintr(int); 167167465Smp 168167465Smpextern void disabled_cleanup(void *); 169167465Smpextern void pintr_disabled_restore(void *); 170167465Smpextern void pintr_push_enable(int *); 171167465Smp 17259243Sobrien#endif /* _h_tc_sig */ 173