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