1/* 2 * sigstat - print out useful information about signal arguments 3 * 4 * Chet Ramey 5 * chet@po.cwru.edu 6 */ 7 8/* Copyright (C) 1991-2002 Free Software Foundation, Inc. 9 10 This file is part of GNU Bash, the Bourne Again SHell. 11 12 Bash is free software; you can redistribute it and/or modify it under 13 the terms of the GNU General Public License as published by the Free 14 Software Foundation; either version 2, or (at your option) any later 15 version. 16 17 Bash is distributed in the hope that it will be useful, but WITHOUT ANY 18 WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20 for more details. 21 22 You should have received a copy of the GNU General Public License along 23 with Bash; see the file COPYING. If not, write to the Free Software 24 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ 25 26#include <sys/types.h> 27#include <signal.h> 28#include <stdio.h> 29 30extern char *strrchr(); 31static char *signames[NSIG]; 32 33char *progname; 34 35void sigstat(); 36 37main(argc, argv) 38int argc; 39char **argv; 40{ 41 register int i; 42 char *t; 43 44 if (t = strrchr(argv[0], '/')) 45 progname = ++t; 46 else 47 progname = argv[0]; 48 init_signames(); 49 if (argc == 1) { 50 for (i = 1; i < NSIG; i++) 51 sigstat(i); 52 exit(0); 53 } 54 for (i = 1; i < argc; i++) 55 sigstat(atoi(argv[i])); 56 exit(0); 57} 58 59void 60sigstat(sig) 61int sig; 62{ 63 struct sigaction oact; 64 char *signame; 65 sigset_t set, oset; 66 int blocked; 67 68 if (sig < 0 || sig >= NSIG) { 69 fprintf(stderr, "%s: %d: signal out of range\n", progname, sig); 70 return; 71 } 72 signame = signames[sig]; 73 sigemptyset(&oset); 74 sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &oset); 75 if (sigismember(&oset, sig)) 76 printf("%s: signal is blocked\n", signame); 77 sigaction(sig, (struct sigaction *)NULL, &oact); 78 if (oact.sa_handler == SIG_IGN) 79 printf("%s: signal is ignored\n", signame); 80 else if (oact.sa_handler == SIG_DFL) 81 printf("%s: signal is defaulted\n", signame); 82 else 83 printf("%s: signal is trapped (?)\n", signame); 84} 85 86init_signames() 87{ 88 register int i; 89 bzero(signames, sizeof(signames)); 90 91#if defined (SIGHUP) /* hangup */ 92 signames[SIGHUP] = "SIGHUP"; 93#endif 94#if defined (SIGINT) /* interrupt */ 95 signames[SIGINT] = "SIGINT"; 96#endif 97#if defined (SIGQUIT) /* quit */ 98 signames[SIGQUIT] = "SIGQUIT"; 99#endif 100#if defined (SIGILL) /* illegal instruction (not reset when caught) */ 101 signames[SIGILL] = "SIGILL"; 102#endif 103#if defined (SIGTRAP) /* trace trap (not reset when caught) */ 104 signames[SIGTRAP] = "SIGTRAP"; 105#endif 106#if defined (SIGABRT) /* */ 107 signames[SIGABRT] = "SIGABRT"; 108#endif 109#if defined (SIGIOT) /* IOT instruction */ 110 signames[SIGIOT] = "SIGIOT"; 111#endif 112#if defined (SIGEMT) /* EMT instruction */ 113 signames[SIGEMT] = "SIGEMT"; 114#endif 115#if defined (SIGFPE) /* floating point exception */ 116 signames[SIGFPE] = "SIGFPE"; 117#endif 118#if defined (SIGKILL) /* kill (cannot be caught or ignored) */ 119 signames[SIGKILL] = "SIGKILL"; 120#endif 121#if defined (SIGBUS) /* bus error */ 122 signames[SIGBUS] = "SIGBUS"; 123#endif 124#if defined (SIGSEGV) /* segmentation violation */ 125 signames[SIGSEGV] = "SIGSEGV"; 126#endif 127#if defined (SIGSYS) /* bad argument to system call */ 128 signames[SIGSYS] = "SIGSYS"; 129#endif 130#if defined (SIGPIPE) /* write on a pipe with no one to read it */ 131 signames[SIGPIPE] = "SIGPIPE"; 132#endif 133#if defined (SIGALRM) /* alarm clock */ 134 signames[SIGALRM] = "SIGALRM"; 135#endif 136#if defined (SIGTERM) /* software termination signal from kill */ 137 signames[SIGTERM] = "SIGTERM"; 138#endif 139#if defined (SIGCLD) /* Like SIGCHLD. */ 140 signames[SIGCLD] = "SIGCLD"; 141#endif 142#if defined (SIGPWR) /* Magic thing for some machines. */ 143 signames[SIGPWR] = "SIGPWR"; 144#endif 145#if defined (SIGPOLL) /* For keyboard input? */ 146 signames[SIGPOLL] = "SIGPOLL"; 147#endif 148#if defined (SIGURG) /* urgent condition on IO channel */ 149 signames[SIGURG] = "SIGURG"; 150#endif 151#if defined (SIGSTOP) /* sendable stop signal not from tty */ 152 signames[SIGSTOP] = "SIGSTOP"; 153#endif 154#if defined (SIGTSTP) /* stop signal from tty */ 155 signames[SIGTSTP] = "SIGTSTP"; 156#endif 157#if defined (SIGCONT) /* continue a stopped process */ 158 signames[SIGCONT] = "SIGCONT"; 159#endif 160#if defined (SIGCHLD) /* to parent on child stop or exit */ 161 signames[SIGCHLD] = "SIGCHLD"; 162#endif 163#if defined (SIGTTIN) /* to readers pgrp upon background tty read */ 164 signames[SIGTTIN] = "SIGTTIN"; 165#endif 166#if defined (SIGTTOU) /* like TTIN for output if (tp->t_local<OSTOP) */ 167 signames[SIGTTOU] = "SIGTTOU"; 168#endif 169#if defined (SIGIO) /* input/output possible signal */ 170 signames[SIGIO] = "SIGIO"; 171#endif 172#if defined (SIGXCPU) /* exceeded CPU time limit */ 173 signames[SIGXCPU] = "SIGXCPU"; 174#endif 175#if defined (SIGXFSZ) /* exceeded file size limit */ 176 signames[SIGXFSZ] = "SIGXFSZ"; 177#endif 178#if defined (SIGVTALRM) /* virtual time alarm */ 179 signames[SIGVTALRM] = "SIGVTALRM"; 180#endif 181#if defined (SIGPROF) /* profiling time alarm */ 182 signames[SIGPROF] = "SIGPROF"; 183#endif 184#if defined (SIGWINCH) /* window changed */ 185 signames[SIGWINCH] = "SIGWINCH"; 186#endif 187#if defined (SIGLOST) /* resource lost (eg, record-lock lost) */ 188 signames[SIGLOST] = "SIGLOST"; 189#endif 190#if defined (SIGUSR1) /* user defined signal 1 */ 191 signames[SIGUSR1] = "SIGUSR1"; 192#endif 193#if defined (SIGUSR2) /* user defined signal 2 */ 194 signames[SIGUSR2] = "SIGUSR2"; 195#endif 196#if defined (SIGMSG) /* HFT input data pending */ 197 signames[SIGMSG] = "SIGMSG"; 198#endif 199#if defined (SIGPWR) /* power failure imminent (save your data) */ 200 signames[SIGPWR] = "SIGPWR"; 201#endif 202#if defined (SIGDANGER) /* system crash imminent */ 203 signames[SIGDANGER] = "SIGDANGER"; 204#endif 205#if defined (SIGMIGRATE) /* migrate process to another CPU */ 206 signames[SIGMIGRATE] = "SIGMIGRATE"; 207#endif 208#if defined (SIGPRE) /* programming error */ 209 signames[SIGPRE] = "SIGPRE"; 210#endif 211#if defined (SIGGRANT) /* HFT monitor mode granted */ 212 signames[SIGGRANT] = "SIGGRANT"; 213#endif 214#if defined (SIGRETRACT) /* HFT monitor mode retracted */ 215 signames[SIGRETRACT] = "SIGRETRACT"; 216#endif 217#if defined (SIGSOUND) /* HFT sound sequence has completed */ 218 signames[SIGSOUND] = "SIGSOUND"; 219#endif 220 221 for (i = 0; i < NSIG; i++) 222 if (signames[i] == (char *)NULL) { 223 signames[i] = (char *)malloc (16);; 224 sprintf (signames[i], "signal %d", i); 225 } 226} 227