1
|
1 // sighandlers.cc -*- C++ -*- |
|
2 /* |
|
3 |
529
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
834
|
28 #include <sys/types.h> |
|
29 #ifdef HAVE_UNISTD_H |
|
30 #include <unistd.h> |
|
31 #endif |
635
|
32 #include <new.h> |
1
|
33 #include <signal.h> |
|
34 |
|
35 #include "sighandlers.h" |
|
36 #include "octave.h" |
|
37 #include "error.h" |
|
38 #include "utils.h" |
|
39 |
|
40 // Nonzero means we have already printed a message for this series of |
|
41 // SIGPIPES. We assume that the writer will eventually give up. |
|
42 int pipe_handler_error_count = 0; |
|
43 |
|
44 // Nonzero means we can be interrupted. |
|
45 int can_interrupt = 0; |
|
46 |
|
47 static void |
|
48 my_friendly_exit (const char *sig_name, int sig_number) |
|
49 { |
886
|
50 error ("%s -- stopping myself...", sig_name); |
1
|
51 clean_up_and_exit (sig_number); |
|
52 } |
|
53 |
635
|
54 // I know, not really a signal handler. |
|
55 |
|
56 static void |
|
57 octave_new_handler (void) |
|
58 { |
|
59 error ("new: virtual memory exhausted -- stopping myself"); |
|
60 clean_up_and_exit (1); |
|
61 } |
|
62 |
1
|
63 static RETSIGTYPE |
834
|
64 generic_sig_handler (int i) |
1
|
65 { |
834
|
66 my_friendly_exit (sys_siglist[i], i); |
1
|
67 |
834
|
68 #if RETSIGTYPE == void |
|
69 return; |
|
70 #else |
|
71 return 0; |
|
72 #endif |
1
|
73 } |
|
74 |
635
|
75 // Handle SIGINT by restarting the parser (see octave.cc). |
|
76 |
834
|
77 // XXX FIXME XXX -- it would probably be good to try to use POSIX |
|
78 // signal interface if it is available. |
|
79 |
1
|
80 static RETSIGTYPE |
|
81 sigint_handler (int i) |
|
82 { |
834
|
83 // Can this ever cause trouble on systems that don't forget signal |
|
84 // handlers when they are invoked? |
|
85 |
|
86 signal (SIGINT, sigint_handler); |
|
87 |
1
|
88 if (can_interrupt) |
|
89 { |
|
90 jump_to_top_level (); |
|
91 panic_impossible (); |
|
92 } |
|
93 |
|
94 #if RETSIGTYPE == void |
|
95 return; |
|
96 #else |
|
97 return 0; |
|
98 #endif |
|
99 } |
|
100 |
|
101 static RETSIGTYPE |
|
102 sigpipe_handler (int i) |
|
103 { |
834
|
104 // Can this ever cause trouble on systems that don't forget signal |
|
105 // handlers when they are invoked? |
|
106 |
|
107 signal (SIGPIPE, sigpipe_handler); |
|
108 |
1
|
109 if (pipe_handler_error_count++ == 0) |
529
|
110 message (0, "broken pipe"); |
1
|
111 |
|
112 // Don\'t loop forever on account of this. |
|
113 if (pipe_handler_error_count > 100) |
|
114 jump_to_top_level (); |
|
115 |
|
116 #if RETSIGTYPE == void |
|
117 return; |
|
118 #else |
|
119 return 0; |
|
120 #endif |
|
121 } |
|
122 |
635
|
123 // Install all the handlers for the signals we might care about. |
|
124 |
1
|
125 void |
|
126 install_signal_handlers (void) |
|
127 { |
635
|
128 set_new_handler (octave_new_handler); |
|
129 |
1
|
130 #ifdef SIGABRT |
834
|
131 signal (SIGABRT, generic_sig_handler); |
1
|
132 #endif |
|
133 |
|
134 #ifdef SIGALRM |
834
|
135 signal (SIGALRM, generic_sig_handler); |
1
|
136 #endif |
|
137 |
|
138 #ifdef SIGBUS |
834
|
139 signal (SIGBUS, generic_sig_handler); |
1
|
140 #endif |
|
141 |
|
142 #ifdef SIGEMT |
834
|
143 signal (SIGEMT, generic_sig_handler); |
1
|
144 #endif |
|
145 |
|
146 #ifdef SIGFPE |
834
|
147 signal (SIGFPE, generic_sig_handler); |
1
|
148 #endif |
|
149 |
|
150 #ifdef SIGHUP |
834
|
151 signal (SIGHUP, generic_sig_handler); |
1
|
152 #endif |
|
153 |
|
154 #ifdef SIGILL |
834
|
155 signal (SIGILL, generic_sig_handler); |
1
|
156 #endif |
|
157 |
|
158 #ifdef SIGINT |
|
159 signal (SIGINT, sigint_handler); |
|
160 #endif |
|
161 |
|
162 #ifdef SIGIOT |
834
|
163 signal (SIGIOT, generic_sig_handler); |
1
|
164 #endif |
|
165 |
|
166 #ifdef SIGLOST |
834
|
167 signal (SIGLOST, generic_sig_handler); |
1
|
168 #endif |
|
169 |
|
170 #ifdef SIGPIPE |
|
171 signal (SIGPIPE, sigpipe_handler); |
|
172 #endif |
|
173 |
|
174 #ifdef SIGPOLL |
895
|
175 signal (SIGPOLL, SIG_IGN); |
1
|
176 #endif |
|
177 |
|
178 #ifdef SIGPROF |
834
|
179 signal (SIGPROF, generic_sig_handler); |
1
|
180 #endif |
|
181 |
|
182 #ifdef SIGQUIT |
834
|
183 signal (SIGQUIT, generic_sig_handler); |
1
|
184 #endif |
|
185 |
|
186 #ifdef SIGSEGV |
834
|
187 signal (SIGSEGV, generic_sig_handler); |
1
|
188 #endif |
|
189 |
|
190 #ifdef SIGSYS |
834
|
191 signal (SIGSYS, generic_sig_handler); |
1
|
192 #endif |
|
193 |
|
194 #ifdef SIGTERM |
834
|
195 signal (SIGTERM, generic_sig_handler); |
1
|
196 #endif |
|
197 |
|
198 #ifdef SIGTRAP |
834
|
199 signal (SIGTRAP, generic_sig_handler); |
1
|
200 #endif |
|
201 |
|
202 #ifdef SIGUSR1 |
834
|
203 signal (SIGUSR1, generic_sig_handler); |
1
|
204 #endif |
|
205 |
|
206 #ifdef SIGUSR2 |
834
|
207 signal (SIGUSR2, generic_sig_handler); |
1
|
208 #endif |
|
209 |
|
210 #ifdef SIGVTALRM |
834
|
211 signal (SIGVTALRM, generic_sig_handler); |
1
|
212 #endif |
|
213 |
895
|
214 #ifdef SIGIO |
|
215 signal (SIGIO, SIG_IGN); |
|
216 #endif |
|
217 |
1
|
218 #ifdef SIGXCPU |
834
|
219 signal (SIGXCPU, generic_sig_handler); |
1
|
220 #endif |
|
221 |
|
222 #ifdef SIGXFSZ |
834
|
223 signal (SIGXFSZ, generic_sig_handler); |
1
|
224 #endif |
|
225 } |
|
226 |
886
|
227 #ifndef HAVE_SYS_SIGLIST |
839
|
228 char *sys_siglist[NSIG + 1] = |
|
229 { |
|
230 #ifdef AIX |
|
231 /* AIX has changed the signals a bit */ |
|
232 "bogus signal", /* 0 */ |
|
233 "hangup", /* 1 SIGHUP */ |
|
234 "interrupt", /* 2 SIGINT */ |
|
235 "quit", /* 3 SIGQUIT */ |
|
236 "illegal instruction", /* 4 SIGILL */ |
|
237 "trace trap", /* 5 SIGTRAP */ |
|
238 "IOT instruction", /* 6 SIGIOT */ |
|
239 "crash likely", /* 7 SIGDANGER */ |
|
240 "floating point exception", /* 8 SIGFPE */ |
|
241 "kill", /* 9 SIGKILL */ |
|
242 "bus error", /* 10 SIGBUS */ |
|
243 "segmentation violation", /* 11 SIGSEGV */ |
|
244 "bad argument to system call", /* 12 SIGSYS */ |
|
245 "write on a pipe with no one to read it", /* 13 SIGPIPE */ |
|
246 "alarm clock", /* 14 SIGALRM */ |
|
247 "software termination signum", /* 15 SIGTERM */ |
|
248 "user defined signal 1", /* 16 SIGUSR1 */ |
|
249 "user defined signal 2", /* 17 SIGUSR2 */ |
|
250 "death of a child", /* 18 SIGCLD */ |
|
251 "power-fail restart", /* 19 SIGPWR */ |
|
252 "bogus signal", /* 20 */ |
|
253 "bogus signal", /* 21 */ |
|
254 "bogus signal", /* 22 */ |
|
255 "bogus signal", /* 23 */ |
|
256 "bogus signal", /* 24 */ |
|
257 "LAN I/O interrupt", /* 25 SIGAIO */ |
|
258 "PTY I/O interrupt", /* 26 SIGPTY */ |
|
259 "I/O intervention required", /* 27 SIGIOINT */ |
|
260 "HFT grant", /* 28 SIGGRANT */ |
|
261 "HFT retract", /* 29 SIGRETRACT */ |
|
262 "HFT sound done", /* 30 SIGSOUND */ |
|
263 "HFT input ready", /* 31 SIGMSG */ |
|
264 #else /* not AIX */ |
|
265 "bogus signal", /* 0 */ |
|
266 "hangup", /* 1 SIGHUP */ |
|
267 "interrupt", /* 2 SIGINT */ |
|
268 "quit", /* 3 SIGQUIT */ |
|
269 "illegal instruction", /* 4 SIGILL */ |
|
270 "trace trap", /* 5 SIGTRAP */ |
|
271 "IOT instruction", /* 6 SIGIOT */ |
|
272 "EMT instruction", /* 7 SIGEMT */ |
|
273 "floating point exception", /* 8 SIGFPE */ |
|
274 "kill", /* 9 SIGKILL */ |
|
275 "bus error", /* 10 SIGBUS */ |
|
276 "segmentation violation", /* 11 SIGSEGV */ |
|
277 "bad argument to system call", /* 12 SIGSYS */ |
|
278 "write on a pipe with no one to read it", /* 13 SIGPIPE */ |
|
279 "alarm clock", /* 14 SIGALRM */ |
|
280 "software termination signum", /* 15 SIGTERM */ |
|
281 "user defined signal 1", /* 16 SIGUSR1 */ |
|
282 "user defined signal 2", /* 17 SIGUSR2 */ |
|
283 "death of a child", /* 18 SIGCLD */ |
|
284 "power-fail restart", /* 19 SIGPWR */ |
|
285 #ifdef sun |
|
286 "window size change", /* 20 SIGWINCH */ |
|
287 "urgent socket condition", /* 21 SIGURG */ |
|
288 "pollable event occured", /* 22 SIGPOLL */ |
|
289 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */ |
|
290 "user stop requested from tty", /* 24 SIGTSTP */ |
|
291 "stopped process has been continued", /* 25 SIGCONT */ |
|
292 "background tty read attempted", /* 26 SIGTTIN */ |
|
293 "background tty write attempted", /* 27 SIGTTOU */ |
|
294 "virtual timer expired", /* 28 SIGVTALRM */ |
|
295 "profiling timer expired", /* 29 SIGPROF */ |
|
296 "exceeded cpu limit", /* 30 SIGXCPU */ |
|
297 "exceeded file size limit", /* 31 SIGXFSZ */ |
|
298 "process's lwps are blocked", /* 32 SIGWAITING */ |
|
299 "special signal used by thread library", /* 33 SIGLWP */ |
|
300 #ifdef SIGFREEZE |
|
301 "Special Signal Used By CPR", /* 34 SIGFREEZE */ |
|
302 #endif |
|
303 #ifdef SIGTHAW |
|
304 "Special Signal Used By CPR", /* 35 SIGTHAW */ |
|
305 #endif |
|
306 #endif /* sun */ |
|
307 #endif /* not AIX */ |
|
308 0 |
|
309 }; |
|
310 #endif |
|
311 |
1
|
312 /* |
|
313 ;;; Local Variables: *** |
|
314 ;;; mode: C++ *** |
|
315 ;;; page-delimiter: "^/\\*" *** |
|
316 ;;; End: *** |
|
317 */ |