1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1230
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
2536
|
27 #include <cstdlib> |
|
28 |
3503
|
29 #include <iostream> |
1344
|
30 #include <new> |
|
31 |
1350
|
32 #ifdef HAVE_UNISTD_H |
2442
|
33 #ifdef HAVE_SYS_TYPES_H |
834
|
34 #include <sys/types.h> |
2442
|
35 #endif |
834
|
36 #include <unistd.h> |
|
37 #endif |
1343
|
38 |
3281
|
39 #include "cmd-edit.h" |
4153
|
40 #include "quit.h" |
3281
|
41 |
4185
|
42 #include "defun.h" |
1352
|
43 #include "error.h" |
1373
|
44 #include "load-save.h" |
4294
|
45 #include "oct-map.h" |
2091
|
46 #include "pager.h" |
4185
|
47 #include "pt-bp.h" |
1
|
48 #include "sighandlers.h" |
4787
|
49 #include "sysdep.h" |
1352
|
50 #include "syswait.h" |
2091
|
51 #include "toplev.h" |
1
|
52 #include "utils.h" |
|
53 |
|
54 // Nonzero means we have already printed a message for this series of |
|
55 // SIGPIPES. We assume that the writer will eventually give up. |
|
56 int pipe_handler_error_count = 0; |
|
57 |
3018
|
58 // TRUE means we can be interrupted. |
|
59 bool can_interrupt = false; |
1
|
60 |
4185
|
61 // TRUE means we should try to enter the debugger on SIGINT. |
|
62 static bool Vdebug_on_interrupt = false; |
|
63 |
4449
|
64 // Allow users to avoid writing octave-core for SIGHUP (sent by |
|
65 // closing gnome-terminal, for example). Note that this variable has |
|
66 // no effect if Vcrash_dumps_octave_core is FALSE. |
|
67 static bool Vsighup_dumps_octave_core; |
|
68 |
|
69 // Similar to Vsighup_dumps_octave_core, but for SIGTERM signal. |
|
70 static bool Vsigterm_dumps_octave_core; |
|
71 |
2469
|
72 #if RETSIGTYPE == void |
|
73 #define SIGHANDLER_RETURN(status) return |
|
74 #else |
|
75 #define SIGHANDLER_RETURN(status) return status |
|
76 #endif |
|
77 |
2554
|
78 #if defined (MUST_REINSTALL_SIGHANDLERS) |
|
79 #define MAYBE_REINSTALL_SIGHANDLER(sig, handler) \ |
|
80 octave_set_signal_handler (sig, handler) |
2931
|
81 #define REINSTALL_USES_SIG 1 |
2554
|
82 #else |
|
83 #define MAYBE_REINSTALL_SIGHANDLER(sig, handler) \ |
|
84 do { } while (0) |
|
85 #endif |
|
86 |
|
87 #if defined (__EMX__) |
2626
|
88 #define MAYBE_ACK_SIGNAL(sig) \ |
2554
|
89 octave_set_signal_handler (sig, SIG_ACK) |
2931
|
90 #define ACK_USES_SIG 1 |
2554
|
91 #else |
2626
|
92 #define MAYBE_ACK_SIGNAL(sig) \ |
2554
|
93 do { } while (0) |
|
94 #endif |
|
95 |
5142
|
96 // List of signals we have caught since last call to octave_signal_handler. |
|
97 static bool octave_signals_caught[NSIG]; |
|
98 |
|
99 // Called from OCTAVE_QUIT to actually do something about the signals |
|
100 // we have caught. |
|
101 |
|
102 void |
|
103 octave_signal_handler (void) |
|
104 { |
|
105 // The list of signals is relatively short, so we will just go |
|
106 // linearly through the list. |
|
107 |
|
108 for (int i = 0; i < NSIG; i++) |
|
109 { |
|
110 if (octave_signals_caught[i]) |
|
111 { |
|
112 octave_signals_caught[i] = false; |
|
113 |
|
114 switch (i) |
|
115 { |
|
116 case SIGCHLD: |
|
117 octave_child_list::reap (); |
|
118 break; |
|
119 |
|
120 case SIGFPE: |
|
121 std::cerr << "warning: floating point exception -- trying to return to prompt" << std::endl; |
|
122 break; |
|
123 |
|
124 case SIGPIPE: |
|
125 std::cerr << "warning: broken pipe -- some output may be lost" << std::endl; |
|
126 break; |
|
127 } |
|
128 } |
|
129 } |
|
130 } |
|
131 |
1
|
132 static void |
4787
|
133 my_friendly_exit (const char *sig_name, int sig_number, |
|
134 bool save_vars = true) |
1
|
135 { |
2536
|
136 static bool been_there_done_that = false; |
|
137 |
|
138 if (been_there_done_that) |
|
139 { |
2554
|
140 #if defined (SIGABRT) |
2536
|
141 octave_set_signal_handler (SIGABRT, SIG_DFL); |
|
142 #endif |
|
143 |
3644
|
144 std::cerr << "panic: attempted clean up apparently failed -- aborting...\n"; |
2536
|
145 abort (); |
|
146 } |
|
147 else |
|
148 { |
|
149 been_there_done_that = true; |
1373
|
150 |
3644
|
151 std::cerr << "panic: " << sig_name << " -- stopping myself...\n"; |
2536
|
152 |
4787
|
153 if (save_vars) |
4791
|
154 dump_octave_core (); |
2536
|
155 |
3162
|
156 if (sig_number < 0) |
|
157 exit (1); |
|
158 else |
|
159 { |
|
160 octave_set_signal_handler (sig_number, SIG_DFL); |
|
161 |
4092
|
162 #if defined (HAVE_RAISE) |
|
163 raise (sig_number); |
|
164 #elif defined (HAVE_KILL) |
3162
|
165 kill (getpid (), sig_number); |
4092
|
166 #else |
|
167 exit (1); |
|
168 #endif |
3162
|
169 } |
4092
|
170 |
2536
|
171 } |
1
|
172 } |
|
173 |
1446
|
174 sig_handler * |
|
175 octave_set_signal_handler (int sig, sig_handler *handler) |
|
176 { |
|
177 #if defined (HAVE_POSIX_SIGNALS) |
|
178 struct sigaction act, oact; |
5144
|
179 |
1446
|
180 act.sa_handler = handler; |
|
181 act.sa_flags = 0; |
5144
|
182 |
|
183 if (sig == SIGALRM) |
|
184 { |
|
185 #if defined (SA_INTERRUPT) |
|
186 act.sa_flags |= SA_INTERRUPT; |
|
187 #endif |
|
188 } |
|
189 else |
|
190 { |
|
191 #if defined (SA_RESTART) |
|
192 act.sa_flags |= SA_RESTART; |
|
193 #endif |
|
194 } |
|
195 |
1446
|
196 sigemptyset (&act.sa_mask); |
|
197 sigemptyset (&oact.sa_mask); |
5144
|
198 |
1446
|
199 sigaction (sig, &act, &oact); |
5144
|
200 |
1446
|
201 return oact.sa_handler; |
|
202 #else |
|
203 return signal (sig, handler); |
|
204 #endif |
|
205 } |
|
206 |
1
|
207 static RETSIGTYPE |
1446
|
208 generic_sig_handler (int sig) |
1
|
209 { |
1446
|
210 my_friendly_exit (sys_siglist[sig], sig); |
1
|
211 |
2469
|
212 SIGHANDLER_RETURN (0); |
1
|
213 } |
|
214 |
2091
|
215 // Handle SIGCHLD. |
1230
|
216 |
4064
|
217 #ifdef SIGCHLD |
1230
|
218 static RETSIGTYPE |
2092
|
219 sigchld_handler (int /* sig */) |
1230
|
220 { |
2705
|
221 volatile octave_interrupt_handler saved_interrupt_handler |
2554
|
222 = octave_ignore_interrupts (); |
|
223 |
2626
|
224 // I wonder if this is really right, or if SIGCHLD should just be |
|
225 // blocked on OS/2 systems the same as for systems with POSIX signal |
|
226 // functions. |
|
227 |
|
228 #if defined (__EMX__) |
2554
|
229 volatile sig_handler *saved_sigchld_handler |
2626
|
230 = octave_set_signal_handler (SIGCHLD, SIG_IGN); |
2554
|
231 #endif |
|
232 |
2626
|
233 sigset_t set, oset; |
|
234 |
|
235 BLOCK_CHILD (set, oset); |
|
236 |
5142
|
237 if (octave_child_list::wait ()) |
2554
|
238 { |
5142
|
239 // The status of some child changed. |
2209
|
240 |
5142
|
241 octave_signal_caught = 1; |
2197
|
242 |
5142
|
243 octave_signals_caught[SIGCHLD] = true; |
1230
|
244 } |
2469
|
245 |
2600
|
246 octave_set_interrupt_handler (saved_interrupt_handler); |
2554
|
247 |
2626
|
248 UNBLOCK_CHILD (oset); |
|
249 |
|
250 #ifdef __EMX__ |
2554
|
251 octave_set_signal_handler (SIGCHLD, saved_sigchld_handler); |
2475
|
252 #endif |
|
253 |
2626
|
254 MAYBE_ACK_SIGNAL (SIGCHLD); |
2554
|
255 |
|
256 MAYBE_REINSTALL_SIGHANDLER (SIGCHLD, sigchld_handler); |
|
257 |
2469
|
258 SIGHANDLER_RETURN (0); |
1230
|
259 } |
4064
|
260 #endif /* defined(SIGCHLD) */ |
1230
|
261 |
4064
|
262 #ifdef SIGFPE |
1373
|
263 #if defined (__alpha__) |
|
264 static RETSIGTYPE |
1488
|
265 sigfpe_handler (int /* sig */) |
1373
|
266 { |
2626
|
267 MAYBE_ACK_SIGNAL (SIGFPE); |
2554
|
268 |
|
269 MAYBE_REINSTALL_SIGHANDLER (SIGFPE, sigfpe_handler); |
1373
|
270 |
5142
|
271 if (can_interrupt && octave_interrupt_state >= 0) |
|
272 { |
|
273 octave_signal_caught = 1; |
1373
|
274 |
5142
|
275 octave_signals_caught[SIGFPE] = true; |
4182
|
276 |
5142
|
277 octave_interrupt_state++; |
|
278 } |
1373
|
279 |
2469
|
280 SIGHANDLER_RETURN (0); |
1373
|
281 } |
4064
|
282 #endif /* defined(__alpha__) */ |
|
283 #endif /* defined(SIGFPE) */ |
1373
|
284 |
4449
|
285 #if defined (SIGHUP) || defined (SIGTERM) |
|
286 static RETSIGTYPE |
|
287 sig_hup_or_term_handler (int sig) |
|
288 { |
|
289 MAYBE_ACK_SIGNAL (sig); |
|
290 |
|
291 MAYBE_REINSTALL_SIGHANDLER (sig, sig_hup_or_term_handler); |
|
292 |
|
293 switch (sig) |
|
294 { |
|
295 #if defined (SIGHUP) |
|
296 case SIGHUP: |
|
297 { |
|
298 if (Vsighup_dumps_octave_core) |
4791
|
299 dump_octave_core (); |
4449
|
300 } |
|
301 break; |
|
302 #endif |
|
303 |
|
304 #if defined (SIGTERM) |
|
305 case SIGTERM: |
|
306 { |
|
307 if (Vsigterm_dumps_octave_core) |
4791
|
308 dump_octave_core (); |
4449
|
309 } |
|
310 break; |
|
311 #endif |
|
312 |
|
313 default: |
|
314 break; |
|
315 } |
|
316 |
|
317 clean_up_and_exit (0); |
|
318 |
|
319 SIGHANDLER_RETURN (0); |
|
320 } |
|
321 #endif |
|
322 |
3343
|
323 #if 0 |
3281
|
324 #if defined (SIGWINCH) |
|
325 static RETSIGTYPE |
|
326 sigwinch_handler (int /* sig */) |
|
327 { |
|
328 MAYBE_ACK_SIGNAL (SIGWINCH); |
|
329 |
|
330 MAYBE_REINSTALL_SIGHANDLER (SIGWINCH, sigwinch_handler); |
|
331 |
|
332 command_editor::resize_terminal (); |
|
333 |
|
334 SIGHANDLER_RETURN (0); |
|
335 } |
|
336 #endif |
3343
|
337 #endif |
3281
|
338 |
635
|
339 // Handle SIGINT by restarting the parser (see octave.cc). |
2554
|
340 // |
|
341 // This also has to work for SIGBREAK (on systems that have it), so we |
|
342 // use the value of sig, instead of just assuming that it is called |
|
343 // for SIGINT only. |
635
|
344 |
1
|
345 static RETSIGTYPE |
2554
|
346 sigint_handler (int sig) |
1
|
347 { |
2626
|
348 MAYBE_ACK_SIGNAL (sig); |
2554
|
349 |
|
350 MAYBE_REINSTALL_SIGHANDLER (sig, sigint_handler); |
834
|
351 |
4172
|
352 if (! octave_initialized) |
|
353 exit (1); |
|
354 |
1
|
355 if (can_interrupt) |
|
356 { |
4185
|
357 if (Vdebug_on_interrupt) |
|
358 { |
|
359 if (! octave_debug_on_interrupt_state) |
|
360 { |
|
361 octave_debug_on_interrupt_state = true; |
|
362 |
|
363 SIGHANDLER_RETURN (0); |
|
364 } |
|
365 else |
|
366 // Clear the flag and do normal interrupt stuff. |
|
367 octave_debug_on_interrupt_state = false; |
|
368 } |
|
369 |
4153
|
370 if (octave_interrupt_immediately) |
|
371 octave_jump_to_enclosing_context (); |
4429
|
372 else |
4787
|
373 { |
4793
|
374 // If we are already cleaning up from a previous interrupt, |
|
375 // take note of the fact that another interrupt signal has |
|
376 // arrived. |
|
377 |
|
378 if (octave_interrupt_state < 0) |
|
379 octave_interrupt_state = 0; |
|
380 |
5142
|
381 octave_signal_caught = 1; |
4787
|
382 octave_interrupt_state++; |
|
383 |
4791
|
384 if (interactive && octave_interrupt_state == 2) |
|
385 std::cerr << "Press Control-C again to abort." << std::endl; |
4787
|
386 |
4791
|
387 if (octave_interrupt_state >= 3) |
|
388 my_friendly_exit (sys_siglist[sig], sig, true); |
4787
|
389 } |
1
|
390 } |
|
391 |
2469
|
392 SIGHANDLER_RETURN (0); |
1
|
393 } |
|
394 |
4064
|
395 #ifdef SIGPIPE |
1
|
396 static RETSIGTYPE |
1488
|
397 sigpipe_handler (int /* sig */) |
1
|
398 { |
2626
|
399 MAYBE_ACK_SIGNAL (SIGPIPE); |
2554
|
400 |
|
401 MAYBE_REINSTALL_SIGHANDLER (SIGPIPE, sigpipe_handler); |
834
|
402 |
5142
|
403 octave_signal_caught = 1; |
|
404 |
|
405 octave_signals_caught[SIGPIPE] = true; |
1
|
406 |
1358
|
407 // Don't loop forever on account of this. |
|
408 |
5142
|
409 if (pipe_handler_error_count++ > 100 && octave_interrupt_state >= 0) |
4787
|
410 octave_interrupt_state++; |
1
|
411 |
2469
|
412 SIGHANDLER_RETURN (0); |
1
|
413 } |
4064
|
414 #endif /* defined(SIGPIPE) */ |
1
|
415 |
2705
|
416 octave_interrupt_handler |
2554
|
417 octave_catch_interrupts (void) |
|
418 { |
2705
|
419 octave_interrupt_handler retval; |
2554
|
420 |
|
421 #ifdef SIGINT |
2705
|
422 retval.int_handler = octave_set_signal_handler (SIGINT, sigint_handler); |
2554
|
423 #endif |
|
424 |
|
425 #ifdef SIGBREAK |
2705
|
426 retval.brk_handler = octave_set_signal_handler (SIGBREAK, sigint_handler); |
2554
|
427 #endif |
2705
|
428 |
|
429 return retval; |
2554
|
430 } |
|
431 |
2705
|
432 octave_interrupt_handler |
|
433 octave_ignore_interrupts (void) |
2554
|
434 { |
2705
|
435 octave_interrupt_handler retval; |
|
436 |
2554
|
437 #ifdef SIGINT |
2705
|
438 retval.int_handler = octave_set_signal_handler (SIGINT, SIG_IGN); |
2554
|
439 #endif |
|
440 |
|
441 #ifdef SIGBREAK |
2705
|
442 retval.brk_handler = octave_set_signal_handler (SIGBREAK, SIG_IGN); |
2554
|
443 #endif |
2705
|
444 |
|
445 return retval; |
|
446 } |
|
447 |
|
448 octave_interrupt_handler |
|
449 octave_set_interrupt_handler (const volatile octave_interrupt_handler& h) |
|
450 { |
|
451 octave_interrupt_handler retval; |
|
452 |
|
453 #ifdef SIGINT |
|
454 retval.int_handler = octave_set_signal_handler (SIGINT, h.int_handler); |
|
455 #endif |
|
456 |
|
457 #ifdef SIGBREAK |
|
458 retval.brk_handler = octave_set_signal_handler (SIGBREAK, h.brk_handler); |
|
459 #endif |
|
460 |
|
461 return retval; |
1651
|
462 } |
|
463 |
635
|
464 // Install all the handlers for the signals we might care about. |
|
465 |
1
|
466 void |
|
467 install_signal_handlers (void) |
|
468 { |
5142
|
469 for (int i = 0; i < NSIG; i++) |
|
470 octave_signals_caught[i] = false; |
|
471 |
2554
|
472 octave_catch_interrupts (); |
|
473 |
1
|
474 #ifdef SIGABRT |
1446
|
475 octave_set_signal_handler (SIGABRT, generic_sig_handler); |
1
|
476 #endif |
|
477 |
|
478 #ifdef SIGALRM |
1446
|
479 octave_set_signal_handler (SIGALRM, generic_sig_handler); |
1
|
480 #endif |
|
481 |
|
482 #ifdef SIGBUS |
1446
|
483 octave_set_signal_handler (SIGBUS, generic_sig_handler); |
1
|
484 #endif |
|
485 |
1230
|
486 #ifdef SIGCHLD |
1446
|
487 octave_set_signal_handler (SIGCHLD, sigchld_handler); |
1230
|
488 #endif |
|
489 |
3174
|
490 // SIGCLD |
|
491 // SIGCONT |
|
492 |
1
|
493 #ifdef SIGEMT |
1446
|
494 octave_set_signal_handler (SIGEMT, generic_sig_handler); |
1
|
495 #endif |
|
496 |
|
497 #ifdef SIGFPE |
1373
|
498 #if defined (__alpha__) |
1446
|
499 octave_set_signal_handler (SIGFPE, sigfpe_handler); |
1373
|
500 #else |
1446
|
501 octave_set_signal_handler (SIGFPE, generic_sig_handler); |
1
|
502 #endif |
1373
|
503 #endif |
1
|
504 |
|
505 #ifdef SIGHUP |
4449
|
506 octave_set_signal_handler (SIGHUP, sig_hup_or_term_handler); |
1
|
507 #endif |
|
508 |
|
509 #ifdef SIGILL |
1446
|
510 octave_set_signal_handler (SIGILL, generic_sig_handler); |
1
|
511 #endif |
|
512 |
3174
|
513 // SIGINFO |
|
514 // SIGINT |
|
515 |
1
|
516 #ifdef SIGIOT |
1446
|
517 octave_set_signal_handler (SIGIOT, generic_sig_handler); |
1
|
518 #endif |
|
519 |
|
520 #ifdef SIGLOST |
1446
|
521 octave_set_signal_handler (SIGLOST, generic_sig_handler); |
1
|
522 #endif |
|
523 |
|
524 #ifdef SIGPIPE |
1446
|
525 octave_set_signal_handler (SIGPIPE, sigpipe_handler); |
1
|
526 #endif |
|
527 |
|
528 #ifdef SIGPOLL |
1446
|
529 octave_set_signal_handler (SIGPOLL, SIG_IGN); |
1
|
530 #endif |
|
531 |
|
532 #ifdef SIGPROF |
1446
|
533 octave_set_signal_handler (SIGPROF, generic_sig_handler); |
1
|
534 #endif |
|
535 |
3174
|
536 // SIGPWR |
|
537 |
1
|
538 #ifdef SIGQUIT |
1446
|
539 octave_set_signal_handler (SIGQUIT, generic_sig_handler); |
1
|
540 #endif |
|
541 |
|
542 #ifdef SIGSEGV |
1446
|
543 octave_set_signal_handler (SIGSEGV, generic_sig_handler); |
1
|
544 #endif |
|
545 |
3174
|
546 // SIGSTOP |
|
547 |
1
|
548 #ifdef SIGSYS |
1446
|
549 octave_set_signal_handler (SIGSYS, generic_sig_handler); |
1
|
550 #endif |
|
551 |
|
552 #ifdef SIGTERM |
4449
|
553 octave_set_signal_handler (SIGTERM, sig_hup_or_term_handler); |
1
|
554 #endif |
|
555 |
|
556 #ifdef SIGTRAP |
1446
|
557 octave_set_signal_handler (SIGTRAP, generic_sig_handler); |
1
|
558 #endif |
|
559 |
3174
|
560 // SIGTSTP |
|
561 // SIGTTIN |
|
562 // SIGTTOU |
|
563 // SIGURG |
|
564 |
1
|
565 #ifdef SIGUSR1 |
1446
|
566 octave_set_signal_handler (SIGUSR1, generic_sig_handler); |
1
|
567 #endif |
|
568 |
|
569 #ifdef SIGUSR2 |
1446
|
570 octave_set_signal_handler (SIGUSR2, generic_sig_handler); |
1
|
571 #endif |
|
572 |
|
573 #ifdef SIGVTALRM |
1446
|
574 octave_set_signal_handler (SIGVTALRM, generic_sig_handler); |
1
|
575 #endif |
|
576 |
895
|
577 #ifdef SIGIO |
1446
|
578 octave_set_signal_handler (SIGIO, SIG_IGN); |
895
|
579 #endif |
|
580 |
3343
|
581 #if 0 |
3281
|
582 #ifdef SIGWINCH |
|
583 octave_set_signal_handler (SIGWINCH, sigwinch_handler); |
|
584 #endif |
3343
|
585 #endif |
3174
|
586 |
1
|
587 #ifdef SIGXCPU |
1446
|
588 octave_set_signal_handler (SIGXCPU, generic_sig_handler); |
1
|
589 #endif |
|
590 |
|
591 #ifdef SIGXFSZ |
1446
|
592 octave_set_signal_handler (SIGXFSZ, generic_sig_handler); |
1
|
593 #endif |
|
594 } |
|
595 |
4294
|
596 static Octave_map |
|
597 make_sig_struct (void) |
|
598 { |
|
599 Octave_map m; |
|
600 |
|
601 #ifdef SIGABRT |
4675
|
602 m.assign ("ABRT", SIGABRT); |
4294
|
603 #endif |
|
604 |
|
605 #ifdef SIGALRM |
4675
|
606 m.assign ("ALRM", SIGALRM); |
4294
|
607 #endif |
|
608 |
|
609 #ifdef SIGBUS |
4675
|
610 m.assign ("BUS", SIGBUS); |
4294
|
611 #endif |
|
612 |
|
613 #ifdef SIGCHLD |
4675
|
614 m.assign ("CHLD", SIGCHLD); |
4294
|
615 #endif |
|
616 |
|
617 #ifdef SIGCLD |
4675
|
618 m.assign ("CLD", SIGCLD); |
4294
|
619 #endif |
|
620 |
|
621 #ifdef SIGCONT |
4675
|
622 m.assign ("CONT", SIGCONT); |
4294
|
623 #endif |
|
624 |
|
625 #ifdef SIGEMT |
4675
|
626 m.assign ("EMT", SIGEMT); |
4294
|
627 #endif |
|
628 |
|
629 #ifdef SIGFPE |
4675
|
630 m.assign ("FPE", SIGFPE); |
4294
|
631 #endif |
|
632 |
|
633 #ifdef SIGHUP |
4675
|
634 m.assign ("HUP", SIGHUP); |
4294
|
635 #endif |
|
636 |
|
637 #ifdef SIGILL |
4675
|
638 m.assign ("ILL", SIGILL); |
4294
|
639 #endif |
|
640 |
|
641 #ifdef SIGINFO |
4675
|
642 m.assign ("INFO", SIGINFO); |
4294
|
643 #endif |
|
644 |
|
645 #ifdef SIGINT |
4675
|
646 m.assign ("INT", SIGINT); |
4294
|
647 #endif |
|
648 |
|
649 #ifdef SIGIOT |
4675
|
650 m.assign ("IOT", SIGIOT); |
4294
|
651 #endif |
|
652 |
|
653 #ifdef SIGLOST |
4675
|
654 m.assign ("LOST", SIGLOST); |
4294
|
655 #endif |
|
656 |
|
657 #ifdef SIGPIPE |
4675
|
658 m.assign ("PIPE", SIGPIPE); |
4294
|
659 #endif |
|
660 |
|
661 #ifdef SIGPOLL |
4675
|
662 m.assign ("POLL", SIGPOLL); |
4294
|
663 #endif |
|
664 |
|
665 #ifdef SIGPROF |
4675
|
666 m.assign ("PROF", SIGPROF); |
4294
|
667 #endif |
|
668 |
|
669 #ifdef SIGPWR |
4675
|
670 m.assign ("PWR", SIGPWR); |
4294
|
671 #endif |
|
672 |
|
673 #ifdef SIGQUIT |
4675
|
674 m.assign ("QUIT", SIGQUIT); |
4294
|
675 #endif |
|
676 |
|
677 #ifdef SIGSEGV |
4675
|
678 m.assign ("SEGV", SIGSEGV); |
4294
|
679 #endif |
|
680 |
|
681 #ifdef SIGSTOP |
4675
|
682 m.assign ("STOP", SIGSTOP); |
4294
|
683 #endif |
|
684 |
|
685 #ifdef SIGSYS |
4675
|
686 m.assign ("SYS", SIGSYS); |
4294
|
687 #endif |
|
688 |
|
689 #ifdef SIGTERM |
4675
|
690 m.assign ("TERM", SIGTERM); |
4294
|
691 #endif |
|
692 |
|
693 #ifdef SIGTRAP |
4675
|
694 m.assign ("TRAP", SIGTRAP); |
4294
|
695 #endif |
|
696 |
|
697 #ifdef SIGTSTP |
4675
|
698 m.assign ("TSTP", SIGTSTP); |
4294
|
699 #endif |
|
700 |
|
701 #ifdef SIGTTIN |
4675
|
702 m.assign ("TTIN", SIGTTIN); |
4294
|
703 #endif |
|
704 |
|
705 #ifdef SIGTTOU |
4675
|
706 m.assign ("TTOU", SIGTTOU); |
4294
|
707 #endif |
|
708 |
|
709 #ifdef SIGURG |
4675
|
710 m.assign ("URG", SIGURG); |
4294
|
711 #endif |
|
712 |
|
713 #ifdef SIGUSR1 |
4675
|
714 m.assign ("USR1", SIGUSR1); |
4294
|
715 #endif |
|
716 |
|
717 #ifdef SIGUSR2 |
4675
|
718 m.assign ("USR2", SIGUSR2); |
4294
|
719 #endif |
|
720 |
|
721 #ifdef SIGVTALRM |
4675
|
722 m.assign ("VTALRM", SIGVTALRM); |
4294
|
723 #endif |
|
724 |
|
725 #ifdef SIGIO |
4675
|
726 m.assign ("IO", SIGIO); |
4294
|
727 #endif |
|
728 |
|
729 #ifdef SIGWINCH |
4675
|
730 m.assign ("WINCH", SIGWINCH); |
4294
|
731 #endif |
|
732 |
|
733 #ifdef SIGXCPU |
4675
|
734 m.assign ("XCPU", SIGXCPU); |
4294
|
735 #endif |
|
736 |
|
737 #ifdef SIGXFSZ |
4675
|
738 m.assign ("XFSZ", SIGXFSZ); |
4294
|
739 #endif |
|
740 |
|
741 return m; |
|
742 } |
|
743 |
5142
|
744 octave_child_list::octave_child_list_rep *octave_child_list::instance = 0; |
5128
|
745 |
2926
|
746 bool |
|
747 octave_child_list::instance_ok (void) |
|
748 { |
|
749 bool retval = true; |
|
750 |
|
751 if (! instance) |
5142
|
752 instance = new octave_child_list_rep (); |
2926
|
753 |
|
754 if (! instance) |
|
755 { |
|
756 ::error ("unable to create child list object!"); |
|
757 |
|
758 retval = false; |
|
759 } |
|
760 |
|
761 return retval; |
|
762 } |
|
763 |
|
764 void |
5142
|
765 octave_child_list::insert (pid_t pid, octave_child::child_event_handler f) |
|
766 { |
|
767 if (instance_ok ()) |
|
768 instance->insert (pid, f); |
|
769 } |
|
770 |
|
771 void |
|
772 octave_child_list::reap (void) |
2926
|
773 { |
|
774 if (instance_ok ()) |
5142
|
775 instance->reap (); |
|
776 } |
|
777 |
|
778 bool |
|
779 octave_child_list::wait (void) |
|
780 { |
|
781 return (instance_ok ()) ? instance->wait () : false; |
2926
|
782 } |
|
783 |
5142
|
784 class pid_equal |
|
785 { |
|
786 public: |
|
787 |
|
788 pid_equal (pid_t v) : val (v) { } |
|
789 |
|
790 bool operator () (const octave_child& oc) const { return oc.pid == val; } |
|
791 |
|
792 private: |
|
793 |
|
794 pid_t val; |
|
795 }; |
|
796 |
2926
|
797 void |
|
798 octave_child_list::remove (pid_t pid) |
|
799 { |
|
800 if (instance_ok ()) |
5142
|
801 instance->remove_if (pid_equal (pid)); |
2926
|
802 } |
|
803 |
5142
|
804 #define OCL_REP octave_child_list::octave_child_list_rep |
2926
|
805 |
5142
|
806 void |
|
807 OCL_REP::insert (pid_t pid, octave_child::child_event_handler f) |
2926
|
808 { |
5142
|
809 append (octave_child (pid, f)); |
2926
|
810 } |
|
811 |
2209
|
812 void |
5142
|
813 OCL_REP::reap (void) |
2209
|
814 { |
5142
|
815 // Mark the record for PID invalid. |
2209
|
816 |
5142
|
817 for (iterator p = begin (); p != end (); p++) |
|
818 { |
|
819 // The call to the octave_child::child_event_handler might |
|
820 // invalidate the iterator (for example, by calling |
|
821 // octave_child_list::remove), so we increment the iterator |
|
822 // here. |
2209
|
823 |
5142
|
824 octave_child& oc = *p; |
2209
|
825 |
5142
|
826 if (oc.have_status) |
2209
|
827 { |
5142
|
828 oc.have_status = 0; |
|
829 |
|
830 octave_child::child_event_handler f = oc.handler; |
|
831 |
|
832 if (f && f (oc.pid, oc.status)) |
|
833 oc.pid = -1; |
2209
|
834 } |
|
835 } |
|
836 |
5142
|
837 remove_if (pid_equal (-1)); |
2209
|
838 } |
|
839 |
5142
|
840 // Wait on our children and record any changes in their status. |
|
841 |
|
842 bool |
|
843 OCL_REP::wait (void) |
2210
|
844 { |
5142
|
845 bool retval = false; |
2210
|
846 |
5142
|
847 for (iterator p = begin (); p != end (); p++) |
2210
|
848 { |
5142
|
849 octave_child& oc = *p; |
|
850 |
|
851 pid_t pid = oc.pid; |
|
852 |
|
853 if (pid > 0) |
|
854 { |
|
855 int status; |
2210
|
856 |
5142
|
857 if (waitpid (pid, &status, WNOHANG) > 0) |
|
858 { |
|
859 oc.have_status = 1; |
|
860 |
|
861 oc.status = status; |
|
862 |
|
863 retval = true; |
|
864 |
|
865 break; |
|
866 } |
2210
|
867 } |
|
868 } |
|
869 |
5142
|
870 return retval; |
2210
|
871 } |
|
872 |
4185
|
873 static int |
|
874 debug_on_interrupt (void) |
|
875 { |
|
876 Vdebug_on_interrupt = check_preference ("debug_on_interrupt"); |
|
877 |
|
878 return 0; |
|
879 } |
|
880 |
4449
|
881 static int |
|
882 sighup_dumps_octave_core (void) |
|
883 { |
|
884 Vsighup_dumps_octave_core = check_preference ("sighup_dumps_octave_core"); |
|
885 |
|
886 return 0; |
|
887 } |
|
888 |
|
889 static int |
|
890 sigterm_dumps_octave_core (void) |
|
891 { |
|
892 Vsigterm_dumps_octave_core = check_preference ("sigterm_dumps_octave_core"); |
|
893 |
|
894 return 0; |
|
895 } |
|
896 |
4185
|
897 void |
|
898 symbols_of_sighandlers (void) |
|
899 { |
4233
|
900 DEFVAR (debug_on_interrupt, false, debug_on_interrupt, |
4185
|
901 "-*- texinfo -*-\n\ |
|
902 @defvr {Built-in Variable} debug_on_interrupt\n\ |
|
903 If @code{debug_on_interrupt} is nonzero, Octave will try to enter\n\ |
|
904 debugging mode when it receives an interrupt signal (typically\n\ |
|
905 generated with @kbd{C-c}). If a second interrupt signal is received\n\ |
|
906 before reaching the debugging mode, a normal interrupt will occur.\n\ |
|
907 The default value is 0.\n\ |
|
908 @end defvr"); |
4294
|
909 |
4449
|
910 DEFVAR (sighup_dumps_octave_core, true, sighup_dumps_octave_core, |
|
911 "-*- texinfo -*-\n\ |
|
912 @defvr {Built-in Variable} sighup_dumps_octave_core\n\ |
|
913 If this variable is set to a nonzero value and\n\ |
|
914 @code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ |
|
915 current variables the the file \"octave-core\" if it receives a\n\ |
|
916 hangup signal. The default value is 1.\n\ |
|
917 @end defvr"); |
|
918 |
|
919 DEFVAR (sigterm_dumps_octave_core, true, sigterm_dumps_octave_core, |
|
920 "-*- texinfo -*-\n\ |
|
921 @defvr {Built-in Variable} sigterm_dumps_octave_core\n\ |
|
922 If this variable is set to a nonzero value and\n\ |
|
923 @code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ |
|
924 current variables the the file \"octave-core\" if it receives a\n\ |
|
925 terminate signal. The default value is 1.\n\ |
|
926 @end defvr"); |
|
927 |
4294
|
928 DEFCONST (SIG, make_sig_struct (), |
|
929 "-*- texinfo -*-\n\ |
|
930 @defvr {Built-in Variable} SIG\n\ |
|
931 Structure of Unix signal names and their defined values.\n\ |
|
932 @end defvr"); |
4185
|
933 } |
|
934 |
1
|
935 /* |
|
936 ;;; Local Variables: *** |
|
937 ;;; mode: C++ *** |
|
938 ;;; End: *** |
|
939 */ |