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 |
|
28 #include <signal.h> |
|
29 |
|
30 #include "sighandlers.h" |
|
31 #include "octave.h" |
|
32 #include "error.h" |
|
33 #include "utils.h" |
|
34 |
|
35 // Nonzero means we have already printed a message for this series of |
|
36 // SIGPIPES. We assume that the writer will eventually give up. |
|
37 int pipe_handler_error_count = 0; |
|
38 |
|
39 // Nonzero means we can be interrupted. |
|
40 int can_interrupt = 0; |
|
41 |
|
42 static void |
|
43 my_friendly_exit (const char *sig_name, int sig_number) |
|
44 { |
|
45 error ("caught %s -- stopping myself...", sig_name); |
|
46 clean_up_and_exit (sig_number); |
|
47 } |
|
48 |
|
49 /* |
|
50 * Some of these may eventually perform different actions... |
|
51 */ |
|
52 |
|
53 static RETSIGTYPE |
|
54 sigabrt_handler (int i) |
|
55 { |
|
56 my_friendly_exit ("SIGABRT", i); |
|
57 } |
|
58 |
|
59 static RETSIGTYPE |
|
60 sigalrm_handler (int i) |
|
61 { |
|
62 my_friendly_exit ("SIGALRM", i); |
|
63 } |
|
64 |
|
65 static RETSIGTYPE |
|
66 sigbus_handler (int i) |
|
67 { |
|
68 my_friendly_exit ("SIGBUS", i); |
|
69 } |
|
70 |
|
71 static RETSIGTYPE |
|
72 sigemt_handler (int i) |
|
73 { |
|
74 my_friendly_exit ("SIGEMT", i); |
|
75 } |
|
76 |
|
77 static RETSIGTYPE |
|
78 sigfpe_handler (int i) |
|
79 { |
|
80 my_friendly_exit ("SIGFPE", i); |
|
81 } |
|
82 |
|
83 static RETSIGTYPE |
|
84 sighup_handler (int i) |
|
85 { |
|
86 my_friendly_exit ("SIGHUP", i); |
|
87 } |
|
88 |
|
89 static RETSIGTYPE |
|
90 sigill_handler (int i) |
|
91 { |
|
92 my_friendly_exit ("SIGILL", i); |
|
93 } |
|
94 |
|
95 /* |
|
96 * Handle SIGINT by restarting the parser (see octave.cc). |
|
97 */ |
|
98 static RETSIGTYPE |
|
99 sigint_handler (int i) |
|
100 { |
|
101 if (can_interrupt) |
|
102 { |
|
103 jump_to_top_level (); |
|
104 panic_impossible (); |
|
105 } |
|
106 |
|
107 #if RETSIGTYPE == void |
|
108 return; |
|
109 #else |
|
110 return 0; |
|
111 #endif |
|
112 } |
|
113 |
|
114 static RETSIGTYPE |
|
115 sigiot_handler (int i) |
|
116 { |
|
117 my_friendly_exit ("SIGIOT", i); |
|
118 } |
|
119 |
|
120 static RETSIGTYPE |
|
121 siglost_handler (int i) |
|
122 { |
|
123 my_friendly_exit ("SIGLOST", i); |
|
124 } |
|
125 |
|
126 static RETSIGTYPE |
|
127 sigpipe_handler (int i) |
|
128 { |
|
129 if (pipe_handler_error_count++ == 0) |
529
|
130 message (0, "broken pipe"); |
1
|
131 |
|
132 // Don\'t loop forever on account of this. |
|
133 if (pipe_handler_error_count > 100) |
|
134 jump_to_top_level (); |
|
135 |
|
136 #if RETSIGTYPE == void |
|
137 return; |
|
138 #else |
|
139 return 0; |
|
140 #endif |
|
141 } |
|
142 |
|
143 static RETSIGTYPE |
|
144 sigpoll_handler (int i) |
|
145 { |
|
146 my_friendly_exit ("SIGPOLL", i); |
|
147 } |
|
148 |
|
149 static RETSIGTYPE |
|
150 sigprof_handler (int i) |
|
151 { |
|
152 my_friendly_exit ("SIGPROF", i); |
|
153 } |
|
154 |
|
155 static RETSIGTYPE |
|
156 sigquit_handler (int i) |
|
157 { |
|
158 my_friendly_exit ("SIGQUIT", i); |
|
159 } |
|
160 |
|
161 static RETSIGTYPE |
|
162 sigsegv_handler (int i) |
|
163 { |
|
164 my_friendly_exit ("SIGSEGV", i); |
|
165 } |
|
166 |
|
167 static RETSIGTYPE |
|
168 sigsys_handler (int i) |
|
169 { |
|
170 my_friendly_exit ("SIGSYS", i); |
|
171 } |
|
172 |
|
173 static RETSIGTYPE |
|
174 sigterm_handler (int i) |
|
175 { |
|
176 my_friendly_exit ("SIGTERM", i); |
|
177 } |
|
178 |
|
179 static RETSIGTYPE |
|
180 sigtrap_handler (int i) |
|
181 { |
|
182 my_friendly_exit ("SIGTRAP", i); |
|
183 } |
|
184 |
|
185 static RETSIGTYPE |
|
186 sigusr1_handler (int i) |
|
187 { |
|
188 my_friendly_exit ("SIGUSR1", i); |
|
189 } |
|
190 |
|
191 static RETSIGTYPE |
|
192 sigusr2_handler (int i) |
|
193 { |
|
194 my_friendly_exit ("SIGUSR2", i); |
|
195 } |
|
196 |
|
197 static RETSIGTYPE |
|
198 sigvtalrm_handler (int i) |
|
199 { |
|
200 my_friendly_exit ("SIGVTALRM", i); |
|
201 } |
|
202 |
|
203 static RETSIGTYPE |
|
204 sigxcpu_handler (int i) |
|
205 { |
|
206 my_friendly_exit ("SIGXCPU", i); |
|
207 } |
|
208 |
|
209 static RETSIGTYPE |
|
210 sigxfsz_handler (int i) |
|
211 { |
|
212 my_friendly_exit ("SIGXFSZ", i); |
|
213 } |
|
214 |
|
215 /* |
|
216 * Install all the handlers for the signals we might care about. |
|
217 */ |
|
218 void |
|
219 install_signal_handlers (void) |
|
220 { |
|
221 #ifdef SIGABRT |
|
222 signal (SIGABRT, sigabrt_handler); |
|
223 #endif |
|
224 |
|
225 #ifdef SIGALRM |
|
226 signal (SIGALRM, sigalrm_handler); |
|
227 #endif |
|
228 |
|
229 #ifdef SIGBUS |
|
230 signal (SIGBUS, sigbus_handler); |
|
231 #endif |
|
232 |
|
233 #ifdef SIGEMT |
|
234 signal (SIGEMT, sigemt_handler); |
|
235 #endif |
|
236 |
|
237 #ifdef SIGFPE |
|
238 signal (SIGFPE, sigfpe_handler); |
|
239 #endif |
|
240 |
|
241 #ifdef SIGHUP |
|
242 signal (SIGHUP, sighup_handler); |
|
243 #endif |
|
244 |
|
245 #ifdef SIGILL |
|
246 signal (SIGILL, sigill_handler); |
|
247 #endif |
|
248 |
|
249 #ifdef SIGINT |
|
250 signal (SIGINT, sigint_handler); |
|
251 #endif |
|
252 |
|
253 #ifdef SIGIOT |
|
254 signal (SIGIOT, sigiot_handler); |
|
255 #endif |
|
256 |
|
257 #ifdef SIGLOST |
|
258 signal (SIGLOST, siglost_handler); |
|
259 #endif |
|
260 |
|
261 #ifdef SIGPIPE |
|
262 signal (SIGPIPE, sigpipe_handler); |
|
263 #endif |
|
264 |
|
265 #ifdef SIGPOLL |
|
266 signal (SIGPOLL, sigpoll_handler); |
|
267 #endif |
|
268 |
|
269 #ifdef SIGPROF |
|
270 signal (SIGPROF, sigprof_handler); |
|
271 #endif |
|
272 |
|
273 #ifdef SIGQUIT |
|
274 signal (SIGQUIT, sigquit_handler); |
|
275 #endif |
|
276 |
|
277 #ifdef SIGSEGV |
|
278 signal (SIGSEGV, sigsegv_handler); |
|
279 #endif |
|
280 |
|
281 #ifdef SIGSYS |
|
282 signal (SIGSYS, sigsys_handler); |
|
283 #endif |
|
284 |
|
285 #ifdef SIGTERM |
|
286 signal (SIGTERM, sigterm_handler); |
|
287 #endif |
|
288 |
|
289 #ifdef SIGTRAP |
|
290 signal (SIGTRAP, sigtrap_handler); |
|
291 #endif |
|
292 |
|
293 #ifdef SIGUSR1 |
|
294 signal (SIGUSR1, sigusr1_handler); |
|
295 #endif |
|
296 |
|
297 #ifdef SIGUSR2 |
|
298 signal (SIGUSR2, sigusr2_handler); |
|
299 #endif |
|
300 |
|
301 #ifdef SIGVTALRM |
|
302 signal (SIGVTALRM, sigvtalrm_handler); |
|
303 #endif |
|
304 |
|
305 #ifdef SIGXCPU |
|
306 signal (SIGXCPU, sigxcpu_handler); |
|
307 #endif |
|
308 |
|
309 #ifdef SIGXFSZ |
|
310 signal (SIGXFSZ, sigxfsz_handler); |
|
311 #endif |
|
312 } |
|
313 |
|
314 /* |
|
315 ;;; Local Variables: *** |
|
316 ;;; mode: C++ *** |
|
317 ;;; page-delimiter: "^/\\*" *** |
|
318 ;;; End: *** |
|
319 */ |