Commit | Line | Data |
---|---|---|
9b04e79a | 1 | ?RCS: $Id: Signal.U 1 2006-08-24 12:32:52Z rmanfredi $ |
959f3c4c | 2 | ?RCS: |
9b04e79a | 3 | ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi |
41322e17 | 4 | ?RCS: |
65a32477 | 5 | ?RCS: You may redistribute only under the terms of the Artistic License, |
959f3c4c JH |
6 | ?RCS: as specified in the README file that comes with the distribution. |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
65a32477 | 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
9b04e79a | 9 | ?RCS: of the source tree for dist 4.0. |
959f3c4c JH |
10 | ?RCS: |
11 | ?RCS: $Log: Signal.U,v $ | |
12 | ?RCS: Revision 3.0.1.1 1997/02/28 15:20:01 ram | |
13 | ?RCS: patch61: created | |
14 | ?RCS: | |
15 | ?X: | |
16 | ?X: This unit produces three files: | |
17 | ?X: 1- A signal.c file, which, when compiled and run, produces an output like: | |
18 | ?X: | |
d01edee3 JH |
19 | ?X: HUP 1 |
20 | ?X: INT 2 | |
21 | ?X: QUIT 3 | |
959f3c4c JH |
22 | ?X: etc... |
23 | ?X: | |
24 | ?X: 2- A signal.awk script to parse the output of signal.c, fill | |
25 | ?X: in gaps (up to NSIG) and move duplicates to the end. | |
26 | ?X: 3- A signal_cmd script to compile signal.c and run it | |
d01edee3 | 27 | ?X: through sort -n -k 2 | uniq | awk -f signal.awk. |
73f787d7 | 28 | ?X: (we try also sort -n +1 since some old hosts don't grok sort -k) |
959f3c4c JH |
29 | ?X: (This is called signal_cmd to avoid OS/2 confusion with |
30 | ?X: signal.cmd vs. signal. | |
31 | ?X: The signal_cmd script also falls back on checking signals one at a | |
32 | ?X: time in case the signal.c program fails. On at least one version of | |
41322e17 | 33 | ?X: Linux 2.1.x, the header file #define'd SIGRTMAX to a symbol that |
959f3c4c | 34 | ?X: is not defined by the compiler/linker. :-(. Further, on that same |
41322e17 | 35 | ?X: version of Linux, the user had a defective C-shell that gave an |
959f3c4c JH |
36 | ?X: incorrect list for kill -l, so the fall-back didn't work. |
37 | ?X: | |
38 | ?X: This unit is then used by sig_name.U. | |
39 | ?X: | |
40 | ?MAKE:Signal: test tr rm awk cat grep startsh eunicefix sed sort uniq \ | |
9c11722e MB |
41 | Findhdr cppstdin +cppflags cppminus Compile _o _exe trnl run i_stdlib \ |
42 | sysroot | |
959f3c4c JH |
43 | ?MAKE: -pick add $@ %< |
44 | ?X:all files declared as "public" since they're used from other units | |
45 | ?F:signal.c signal_cmd signal.lst signal signal.awk | |
46 | ?T: xx xxx xxxfiles | |
9b04e79a | 47 | ?LINT:use rm run _o _exe |
959f3c4c | 48 | : Trace out the files included by signal.h, then look for SIGxxx names. |
9b04e79a MB |
49 | ?X: Remove SIGARRAYSIZE used by HPUX. |
50 | ?X: Remove SIGSTKSIZE used by Linux. | |
65a32477 | 51 | ?X: Remove SIGSTKSZ used by POSIX. |
9b04e79a | 52 | ?X: Remove SIGTYP void lines used by OS2. |
ed5d019e | 53 | ?X: Some cpps, like os390, do not give the file name anywhere |
edd6115f JH |
54 | if [ "X$fieldn" = X ]; then |
55 | : Just make some guesses. We check them later. | |
9c11722e | 56 | xxx="$sysroot/usr/include/signal.h $sysroot/usr/include/sys/signal.h" |
edd6115f JH |
57 | else |
58 | xxx=`echo '#include <signal.h>' | | |
959f3c4c | 59 | $cppstdin $cppminus $cppflags 2>/dev/null | |
41322e17 | 60 | $grep '^[ ]*#.*include' | |
9b04e79a MB |
61 | $awk "{print \\$$fieldn}" | $sed 's!"!!g' |\ |
62 | $sed 's!\\\\\\\\!/!g' | $sort | $uniq` | |
edd6115f | 63 | fi |
9b04e79a MB |
64 | ?X: Check this list of files to be sure we have parsed the cpp output ok. |
65 | ?X: This will also avoid potentially non-existent files, such | |
66 | ?X: as ../foo/bar.h | |
959f3c4c JH |
67 | xxxfiles='' |
68 | ?X: Add /dev/null in case the $xxx list is empty. | |
69 | for xx in $xxx /dev/null ; do | |
70 | $test -f "$xx" && xxxfiles="$xxxfiles $xx" | |
71 | done | |
9b04e79a | 72 | ?X: If we have found no files, at least try signal.h |
959f3c4c JH |
73 | case "$xxxfiles" in |
74 | '') xxxfiles=`./findhdr signal.h` ;; | |
75 | esac | |
76 | xxx=`awk ' | |
77 | $1 ~ /^#define$/ && $2 ~ /^SIG[A-Z0-9]*$/ && $2 !~ /SIGARRAYSIZE/ && $2 !~ /SIGSTKSIZE/ && $2 !~ /SIGSTKSZ/ && $3 !~ /void/ { | |
78 | print substr($2, 4, 20) | |
79 | } | |
80 | $1 == "#" && $2 ~ /^define$/ && $3 ~ /^SIG[A-Z0-9]*$/ && $3 !~ /SIGARRAYSIZE/ && $4 !~ /void/ { | |
81 | print substr($3, 4, 20) | |
82 | }' $xxxfiles` | |
83 | : Append some common names just in case the awk scan failed. | |
edd6115f JH |
84 | xxx="$xxx ABRT ALRM BUS CANCEL CHLD CLD CONT DIL EMT FPE" |
85 | xxx="$xxx FREEZE HUP ILL INT IO IOT KILL LOST LWP PHONE" | |
86 | xxx="$xxx PIPE POLL PROF PWR QUIT RTMAX RTMIN SEGV STKFLT STOP" | |
87 | xxx="$xxx SYS TERM THAW TRAP TSTP TTIN TTOU URG USR1 USR2" | |
88 | xxx="$xxx USR3 USR4 VTALRM WAITING WINCH WIND WINDOW XCPU XFSZ" | |
89 | ||
959f3c4c | 90 | : generate a few handy files for later |
1273bb5e | 91 | $cat > signal.c <<EOCP |
959f3c4c JH |
92 | #include <sys/types.h> |
93 | #include <signal.h> | |
1273bb5e JH |
94 | #$i_stdlib I_STDLIB |
95 | #ifdef I_STDLIB | |
96 | #include <stdlib.h> | |
97 | #endif | |
959f3c4c JH |
98 | #include <stdio.h> |
99 | int main() { | |
100 | ||
101 | /* Strange style to avoid deeply-nested #if/#else/#endif */ | |
102 | #ifndef NSIG | |
103 | # ifdef _NSIG | |
104 | # define NSIG (_NSIG) | |
105 | # endif | |
106 | #endif | |
107 | ||
108 | #ifndef NSIG | |
109 | # ifdef SIGMAX | |
110 | # define NSIG (SIGMAX+1) | |
111 | # endif | |
112 | #endif | |
113 | ||
114 | #ifndef NSIG | |
115 | # ifdef SIG_MAX | |
116 | # define NSIG (SIG_MAX+1) | |
117 | # endif | |
118 | #endif | |
119 | ||
120 | #ifndef NSIG | |
8ca72237 JH |
121 | # ifdef _SIG_MAX |
122 | # define NSIG (_SIG_MAX+1) | |
123 | # endif | |
124 | #endif | |
125 | ||
126 | #ifndef NSIG | |
959f3c4c JH |
127 | # ifdef MAXSIG |
128 | # define NSIG (MAXSIG+1) | |
129 | # endif | |
130 | #endif | |
131 | ||
132 | #ifndef NSIG | |
133 | # ifdef MAX_SIG | |
134 | # define NSIG (MAX_SIG+1) | |
135 | # endif | |
136 | #endif | |
137 | ||
138 | #ifndef NSIG | |
139 | # ifdef SIGARRAYSIZE | |
30df046d | 140 | # define NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
959f3c4c JH |
141 | # endif |
142 | #endif | |
143 | ||
144 | #ifndef NSIG | |
145 | # ifdef _sys_nsig | |
146 | # define NSIG (_sys_nsig) /* Solaris 2.5 */ | |
147 | # endif | |
148 | #endif | |
149 | ||
150 | /* Default to some arbitrary number that's big enough to get most | |
151 | of the common signals. | |
152 | */ | |
153 | #ifndef NSIG | |
154 | # define NSIG 50 | |
155 | #endif | |
156 | ||
157 | printf("NSIG %d\n", NSIG); | |
158 | ||
159 | #ifndef JUST_NSIG | |
160 | ||
161 | EOCP | |
162 | ||
163 | echo $xxx | $tr ' ' $trnl | $sort | $uniq | $awk ' | |
164 | { | |
165 | printf "#ifdef SIG"; printf $1; printf "\n" | |
d01edee3 | 166 | printf "printf(\""; printf $1; printf " %%d\\n\",SIG"; |
959f3c4c JH |
167 | printf $1; printf ");\n" |
168 | printf "#endif\n" | |
169 | } | |
170 | END { | |
171 | printf "#endif /* JUST_NSIG */\n"; | |
b8fb7a32 | 172 | printf "exit(0);\n}\n"; |
959f3c4c JH |
173 | } |
174 | ' >>signal.c | |
175 | $cat >signal.awk <<'EOP' | |
176 | BEGIN { ndups = 0 } | |
d01edee3 | 177 | $1 ~ /^NSIG$/ { nsig = $2 } |
de9dd147 | 178 | ($1 !~ /^NSIG$/) && (NF == 2) && ($2 ~ /^[0-9][0-9]*$/) { |
d01edee3 JH |
179 | if ($2 > maxsig) { maxsig = $2 } |
180 | if (sig_name[$2]) { | |
181 | dup_name[ndups] = $1 | |
182 | dup_num[ndups] = $2 | |
41322e17 | 183 | ndups++ |
959f3c4c | 184 | } |
de9dd147 | 185 | else { |
d01edee3 JH |
186 | sig_name[$2] = $1 |
187 | sig_num[$2] = $2 | |
959f3c4c JH |
188 | } |
189 | } | |
41322e17 | 190 | END { |
959f3c4c JH |
191 | if (nsig == 0) { |
192 | nsig = maxsig + 1 | |
193 | } | |
194 | printf("NSIG %d\n", nsig); | |
195 | for (n = 1; n < nsig; n++) { | |
196 | if (sig_name[n]) { | |
197 | printf("%s %d\n", sig_name[n], sig_num[n]) | |
198 | } | |
199 | else { | |
41322e17 | 200 | printf("NUM%d %d\n", n, n) |
959f3c4c JH |
201 | } |
202 | } | |
203 | for (n = 0; n < ndups; n++) { | |
204 | printf("%s %d\n", dup_name[n], dup_num[n]) | |
205 | } | |
206 | } | |
207 | EOP | |
208 | $cat >signal_cmd <<EOS | |
209 | $startsh | |
210 | if $test -s signal.lst; then | |
211 | echo "Using your existing signal.lst file" | |
212 | exit 0 | |
213 | fi | |
214 | xxx="$xxx" | |
215 | EOS | |
9b04e79a MB |
216 | ?X: Avoid variable interpolation problems, especially with |
217 | ?X: xxx, which contains newlines. | |
959f3c4c JH |
218 | $cat >>signal_cmd <<'EOS' |
219 | ||
220 | set signal | |
221 | if eval $compile_ok; then | |
9b04e79a MB |
222 | $run ./signal$_exe | ($sort -n -k 2 2>/dev/null || $sort -n +1) |\ |
223 | $uniq | $awk -f signal.awk >signal.lst | |
959f3c4c JH |
224 | else |
225 | echo "(I can't seem be able to compile the whole test program)" >&4 | |
226 | echo "(I'll try it in little pieces.)" >&4 | |
227 | set signal -DJUST_NSIG | |
228 | if eval $compile_ok; then | |
0f00356b | 229 | $run ./signal$_exe > signal.nsg |
959f3c4c JH |
230 | $cat signal.nsg |
231 | else | |
232 | echo "I can't seem to figure out how many signals you have." >&4 | |
233 | echo "Guessing 50." >&4 | |
234 | echo 'NSIG 50' > signal.nsg | |
235 | fi | |
236 | : Now look at all the signal names, one at a time. | |
237 | for xx in `echo $xxx | $tr ' ' $trnl | $sort | $uniq`; do | |
238 | $cat > signal.c <<EOCP | |
239 | #include <sys/types.h> | |
240 | #include <signal.h> | |
241 | #include <stdio.h> | |
242 | int main() { | |
243 | printf("$xx %d\n", SIG${xx}); | |
244 | return 0; | |
245 | } | |
246 | EOCP | |
247 | set signal | |
248 | if eval $compile; then | |
249 | echo "SIG${xx} found." | |
0f00356b | 250 | $run ./signal$_exe >> signal.ls1 |
959f3c4c JH |
251 | else |
252 | echo "SIG${xx} NOT found." | |
253 | fi | |
254 | done | |
255 | if $test -s signal.ls1; then | |
256 | $cat signal.nsg signal.ls1 | | |
d01edee3 | 257 | $sort -n | $uniq | $awk -f signal.awk >signal.lst |
959f3c4c JH |
258 | fi |
259 | ||
260 | fi | |
261 | if $test -s signal.lst; then | |
262 | : | |
263 | else | |
264 | echo "(AAK! I can't compile the test programs -- Guessing)" >&4 | |
265 | echo 'kill -l' >signal | |
266 | set X `csh -f <signal` | |
267 | $rm -f signal | |
268 | shift | |
269 | case $# in | |
270 | 0) set HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM;; | |
271 | esac | |
272 | echo $@ | $tr ' ' $trnl | \ | |
273 | $awk '{ printf "%s %d\n", $1, ++s; } | |
274 | END { printf "NSIG %d\n", ++s }' >signal.lst | |
275 | fi | |
276 | $rm -f signal.c signal$_exe signal$_o signal.nsg signal.ls1 | |
277 | EOS | |
278 | chmod a+x signal_cmd | |
279 | $eunicefix signal_cmd | |
280 |