xref: /titanic_50/usr/src/lib/libast/common/features/signal.c (revision 020c47705d28102a8df83a43ddf08e34dde21f22)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * AT&T Bell Laboratories
26  *
27  * generate signal features
28  */
29 
30 #include <signal.h>
31 
32 struct _m_
33 {
34 	char*		text;
35 	char*		name;
36 	int		value;
37 };
38 
39 #define elementsof(x)	(sizeof(x)/sizeof(x[0]))
40 
41 static struct _m_ map[] =
42 {
43 #ifdef SIGABRT
44 "Abort",			"ABRT",		SIGABRT,
45 #endif
46 #ifdef SIGAIO
47 "Asynchronous I/O",		"AIO",		SIGAIO,
48 #endif
49 #ifdef SIGALRM
50 "Alarm call",			"ALRM",		SIGALRM,
51 #endif
52 #ifdef SIGAPOLLO
53 "Apollo",			"APOLLO",	SIGAPOLLO,
54 #endif
55 #ifdef SIGBUS
56 "Bus error",			"BUS",		SIGBUS,
57 #endif
58 #ifdef SIGCHLD
59 "Child status change",		"CHLD",		SIGCHLD,
60 #endif
61 #ifdef SIGCLD
62 "Death of child", 		"CLD",		SIGCLD,
63 #endif
64 #ifdef SIGCONT
65 "Stopped process continued",	"CONT",		SIGCONT,
66 #endif
67 #ifdef SIGDANGER
68 "System crash soon",		"DANGER",	SIGDANGER,
69 #endif
70 #ifdef SIGDEBUG
71 "Debug trap",			"DEBUG",	SIGDEBUG,
72 #endif
73 #ifdef SIGDIL
74 "DIL trap",			"DIL",		SIGDIL,
75 #endif
76 #ifdef SIGEMT
77 "EMT trap",			"EMT",		SIGEMT,
78 #endif
79 #ifdef SIGERR
80 "ERR trap",			"ERR",		SIGERR,
81 #endif
82 #ifdef SIGEXIT
83 "Exit",				"EXIT",		SIGEXIT,
84 #endif
85 #ifdef SIGFPE
86 "Floating exception",		"FPE",		SIGFPE,
87 #endif
88 #ifdef SIGFREEZE
89 "CPR freeze",			"FREEZE",	SIGFREEZE,
90 #endif
91 #ifdef SIGHUP
92 "Hangup",			"HUP",		SIGHUP,
93 #endif
94 #ifdef SIGILL
95 "Illegal instruction",		"ILL",		SIGILL,
96 #endif
97 #ifdef SIGINT
98 "Interrupt",			"INT",		SIGINT,
99 #endif
100 #ifdef SIGIO
101 "IO possible",			"IO",		SIGIO,
102 #endif
103 #ifdef SIGIOT
104 "IOT trap",			"IOT",		SIGIOT,
105 #endif
106 #ifdef SIGKILL
107 "Killed",			"KILL",		SIGKILL,
108 #endif
109 #ifdef SIGLAB
110 "Security label changed",	"LAB",		SIGLAB,
111 #endif
112 #ifdef SIGLOST
113 "Resources lost",		"LOST",		SIGLOST,
114 #endif
115 #ifdef SIGLWP
116 "Thread event",			"LWP",		SIGLWP,
117 #endif
118 #ifdef SIGMIGRATE
119 "Migrate process",		"MIGRATE",	SIGMIGRATE,
120 #endif
121 #ifdef SIGPHONE
122 "Phone status change",		"PHONE",	SIGPHONE,
123 #endif
124 #ifdef SIGPIPE
125 "Broken pipe",			"PIPE",		SIGPIPE,
126 #endif
127 #ifdef SIGPOLL
128 "Poll event",			"POLL",		SIGPOLL,
129 #endif
130 #ifdef SIGPROF
131 "Profile timer alarm",		"PROF",		SIGPROF,
132 #endif
133 #ifdef SIGPWR
134 "Power fail",			"PWR",		SIGPWR,
135 #endif
136 #ifdef SIGQUIT
137 "Quit",				"QUIT",		SIGQUIT,
138 #endif
139 #ifdef SIGSEGV
140 "Memory fault",			"SEGV",		SIGSEGV,
141 #endif
142 #ifdef SIGSOUND
143 "Sound completed",		"SOUND",	SIGSOUND,
144 #endif
145 #ifdef SIGSSTOP
146 "Sendable stop",		"SSTOP",	SIGSSTOP,
147 #endif
148 #ifdef gould
149 "Stack overflow",		"STKOV",	28,
150 #endif
151 #ifdef SIGSTOP
152 "Stopped (signal)",		"STOP",		SIGSTOP,
153 #endif
154 #ifdef SIGSYS
155 "Bad system call", 		"SYS",		SIGSYS,
156 #endif
157 #ifdef SIGTERM
158 "Terminated",			"TERM",		SIGTERM,
159 #endif
160 #ifdef SIGTHAW
161 "CPR thaw",			"THAW",		SIGTHAW,
162 #endif
163 #ifdef SIGTINT
164 "Interrupt (terminal)",		"TINT",		SIGTINT,
165 #endif
166 #ifdef SIGTRAP
167 "Trace trap",			"TRAP",		SIGTRAP,
168 #endif
169 #ifdef SIGTSTP
170 "Stopped",			"TSTP",		SIGTSTP,
171 #endif
172 #ifdef SIGTTIN
173 "Stopped (tty input)",		"TTIN",		SIGTTIN,
174 #endif
175 #ifdef SIGTTOU
176 "Stopped (tty output)",		"TTOU",		SIGTTOU,
177 #endif
178 #ifdef SIGURG
179 "Urgent IO",			"URG",		SIGURG,
180 #endif
181 #ifdef SIGUSR1
182 "User signal 1",		"USR1",		SIGUSR1,
183 #endif
184 #ifdef SIGUSR2
185 "User signal 2",		"USR2",		SIGUSR2,
186 #endif
187 #ifdef SIGVTALRM
188 "Virtual timer alarm",		"VTALRM",	SIGVTALRM,
189 #endif
190 #ifdef SIGWAITING
191 "All threads blocked",		"WAITING",	SIGWAITING,
192 #endif
193 #ifdef SIGWINCH
194 "Window change", 		"WINCH",	SIGWINCH,
195 #endif
196 #ifdef SIGWIND
197 "Window change",		"WIND",		SIGWIND,
198 #endif
199 #ifdef SIGWINDOW
200 "Window change",		"WINDOW",	SIGWINDOW,
201 #endif
202 #ifdef SIGXCPU
203 "CPU time limit",		"XCPU",		SIGXCPU,
204 #endif
205 #ifdef SIGXFSZ
206 "File size limit",		"XFSZ",		SIGXFSZ,
207 #endif
208 0
209 };
210 
211 #define RANGE_MIN	(1<<14)
212 #define RANGE_MAX	(1<<13)
213 #define RANGE_RT	(1<<12)
214 
215 #define RANGE_SIG	(~(RANGE_MIN|RANGE_MAX|RANGE_RT))
216 
217 static int		index[64];
218 
219 int
220 main()
221 {
222 	register int	i;
223 	register int	j;
224 	register int	k;
225 	int		n;
226 
227 	k = 0;
228 	for (i = 0; map[i].name; i++)
229 		if ((j = map[i].value) > 0 && j < elementsof(index) && !index[j])
230 		{
231 			if (j > k) k = j;
232 			index[j] = i;
233 		}
234 #ifdef SIGRTMIN
235 	i = SIGRTMIN;
236 #ifdef SIGRTMAX
237 	j = SIGRTMAX;
238 #else
239 	j = i;
240 #endif
241 	if (j >= elementsof(index)) j = elementsof(index) - 1;
242 	if (i <= j && i > 0 && i < elementsof(index) && j > 0 && j < elementsof(index))
243 	{
244 		if (j > k) k = j;
245 		index[i] = RANGE_MIN | RANGE_RT;
246 		n = 1;
247 		while (++i < j)
248 			index[i] = RANGE_RT | n++;
249 		index[j] = RANGE_MAX | RANGE_RT | n;
250 	}
251 #endif
252 	printf("#pragma prototyped\n");
253 	printf("#define SIG_MAX	%d\n", k);
254 	printf("\n");
255 	printf("static const char* const	sig_name[] =\n");
256 	printf("{\n");
257 	for (i = 0; i <= k; i++)
258 		if (!(j = index[i])) printf("	\"%d\",\n", i);
259 		else if (j & RANGE_RT)
260 		{
261 			if (j & RANGE_MIN) printf("	\"RTMIN\",\n");
262 			else if (j & RANGE_MAX) printf("	\"RTMAX\",\n");
263 			else printf("	\"RT%d\",\n", j & RANGE_SIG);
264 		}
265 		else printf("	\"%s\",\n", map[j].name);
266 	printf("	0\n");
267 	printf("};\n");
268 	printf("\n");
269 	printf("static const char* const	sig_text[] =\n");
270 	printf("{\n");
271 	for (i = 0; i <= k; i++)
272 		if (!(j = index[i])) printf("	\"Signal %d\",\n", i);
273 		else if (j & RANGE_RT) printf("	\"Realtime priority %d%s\",\n", j & RANGE_SIG, (j & RANGE_MIN) ? " (lo)" : (j & RANGE_MAX) ? " (hi)" : "");
274 		else printf("	\"%s\",\n", map[j].text);
275 	printf("	0\n");
276 	printf("};\n");
277 	return 0;
278 }
279