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