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; |
|
179 act.sa_handler = handler; |
|
180 act.sa_flags = 0; |
|
181 sigemptyset (&act.sa_mask); |
|
182 sigemptyset (&oact.sa_mask); |
|
183 sigaction (sig, &act, &oact); |
|
184 return oact.sa_handler; |
|
185 #else |
|
186 return signal (sig, handler); |
|
187 #endif |
|
188 } |
|
189 |
1
|
190 static RETSIGTYPE |
1446
|
191 generic_sig_handler (int sig) |
1
|
192 { |
1446
|
193 my_friendly_exit (sys_siglist[sig], sig); |
1
|
194 |
2469
|
195 SIGHANDLER_RETURN (0); |
1
|
196 } |
|
197 |
2091
|
198 // Handle SIGCHLD. |
1230
|
199 |
4064
|
200 #ifdef SIGCHLD |
1230
|
201 static RETSIGTYPE |
2092
|
202 sigchld_handler (int /* sig */) |
1230
|
203 { |
2705
|
204 volatile octave_interrupt_handler saved_interrupt_handler |
2554
|
205 = octave_ignore_interrupts (); |
|
206 |
2626
|
207 // I wonder if this is really right, or if SIGCHLD should just be |
|
208 // blocked on OS/2 systems the same as for systems with POSIX signal |
|
209 // functions. |
|
210 |
|
211 #if defined (__EMX__) |
2554
|
212 volatile sig_handler *saved_sigchld_handler |
2626
|
213 = octave_set_signal_handler (SIGCHLD, SIG_IGN); |
2554
|
214 #endif |
|
215 |
2626
|
216 sigset_t set, oset; |
|
217 |
|
218 BLOCK_CHILD (set, oset); |
|
219 |
5142
|
220 if (octave_child_list::wait ()) |
2554
|
221 { |
5142
|
222 // The status of some child changed. |
2209
|
223 |
5142
|
224 octave_signal_caught = 1; |
2197
|
225 |
5142
|
226 octave_signals_caught[SIGCHLD] = true; |
1230
|
227 } |
2469
|
228 |
2600
|
229 octave_set_interrupt_handler (saved_interrupt_handler); |
2554
|
230 |
2626
|
231 UNBLOCK_CHILD (oset); |
|
232 |
|
233 #ifdef __EMX__ |
2554
|
234 octave_set_signal_handler (SIGCHLD, saved_sigchld_handler); |
2475
|
235 #endif |
|
236 |
2626
|
237 MAYBE_ACK_SIGNAL (SIGCHLD); |
2554
|
238 |
|
239 MAYBE_REINSTALL_SIGHANDLER (SIGCHLD, sigchld_handler); |
|
240 |
2469
|
241 SIGHANDLER_RETURN (0); |
1230
|
242 } |
4064
|
243 #endif /* defined(SIGCHLD) */ |
1230
|
244 |
4064
|
245 #ifdef SIGFPE |
1373
|
246 #if defined (__alpha__) |
|
247 static RETSIGTYPE |
1488
|
248 sigfpe_handler (int /* sig */) |
1373
|
249 { |
2626
|
250 MAYBE_ACK_SIGNAL (SIGFPE); |
2554
|
251 |
|
252 MAYBE_REINSTALL_SIGHANDLER (SIGFPE, sigfpe_handler); |
1373
|
253 |
5142
|
254 if (can_interrupt && octave_interrupt_state >= 0) |
|
255 { |
|
256 octave_signal_caught = 1; |
1373
|
257 |
5142
|
258 octave_signals_caught[SIGFPE] = true; |
4182
|
259 |
5142
|
260 octave_interrupt_state++; |
|
261 } |
1373
|
262 |
2469
|
263 SIGHANDLER_RETURN (0); |
1373
|
264 } |
4064
|
265 #endif /* defined(__alpha__) */ |
|
266 #endif /* defined(SIGFPE) */ |
1373
|
267 |
4449
|
268 #if defined (SIGHUP) || defined (SIGTERM) |
|
269 static RETSIGTYPE |
|
270 sig_hup_or_term_handler (int sig) |
|
271 { |
|
272 MAYBE_ACK_SIGNAL (sig); |
|
273 |
|
274 MAYBE_REINSTALL_SIGHANDLER (sig, sig_hup_or_term_handler); |
|
275 |
|
276 switch (sig) |
|
277 { |
|
278 #if defined (SIGHUP) |
|
279 case SIGHUP: |
|
280 { |
|
281 if (Vsighup_dumps_octave_core) |
4791
|
282 dump_octave_core (); |
4449
|
283 } |
|
284 break; |
|
285 #endif |
|
286 |
|
287 #if defined (SIGTERM) |
|
288 case SIGTERM: |
|
289 { |
|
290 if (Vsigterm_dumps_octave_core) |
4791
|
291 dump_octave_core (); |
4449
|
292 } |
|
293 break; |
|
294 #endif |
|
295 |
|
296 default: |
|
297 break; |
|
298 } |
|
299 |
|
300 clean_up_and_exit (0); |
|
301 |
|
302 SIGHANDLER_RETURN (0); |
|
303 } |
|
304 #endif |
|
305 |
3343
|
306 #if 0 |
3281
|
307 #if defined (SIGWINCH) |
|
308 static RETSIGTYPE |
|
309 sigwinch_handler (int /* sig */) |
|
310 { |
|
311 MAYBE_ACK_SIGNAL (SIGWINCH); |
|
312 |
|
313 MAYBE_REINSTALL_SIGHANDLER (SIGWINCH, sigwinch_handler); |
|
314 |
|
315 command_editor::resize_terminal (); |
|
316 |
|
317 SIGHANDLER_RETURN (0); |
|
318 } |
|
319 #endif |
3343
|
320 #endif |
3281
|
321 |
635
|
322 // Handle SIGINT by restarting the parser (see octave.cc). |
2554
|
323 // |
|
324 // This also has to work for SIGBREAK (on systems that have it), so we |
|
325 // use the value of sig, instead of just assuming that it is called |
|
326 // for SIGINT only. |
635
|
327 |
1
|
328 static RETSIGTYPE |
2554
|
329 sigint_handler (int sig) |
1
|
330 { |
2626
|
331 MAYBE_ACK_SIGNAL (sig); |
2554
|
332 |
|
333 MAYBE_REINSTALL_SIGHANDLER (sig, sigint_handler); |
834
|
334 |
4172
|
335 if (! octave_initialized) |
|
336 exit (1); |
|
337 |
1
|
338 if (can_interrupt) |
|
339 { |
4185
|
340 if (Vdebug_on_interrupt) |
|
341 { |
|
342 if (! octave_debug_on_interrupt_state) |
|
343 { |
|
344 octave_debug_on_interrupt_state = true; |
|
345 |
|
346 SIGHANDLER_RETURN (0); |
|
347 } |
|
348 else |
|
349 // Clear the flag and do normal interrupt stuff. |
|
350 octave_debug_on_interrupt_state = false; |
|
351 } |
|
352 |
4153
|
353 if (octave_interrupt_immediately) |
|
354 octave_jump_to_enclosing_context (); |
4429
|
355 else |
4787
|
356 { |
4793
|
357 // If we are already cleaning up from a previous interrupt, |
|
358 // take note of the fact that another interrupt signal has |
|
359 // arrived. |
|
360 |
|
361 if (octave_interrupt_state < 0) |
|
362 octave_interrupt_state = 0; |
|
363 |
5142
|
364 octave_signal_caught = 1; |
4787
|
365 octave_interrupt_state++; |
|
366 |
4791
|
367 if (interactive && octave_interrupt_state == 2) |
|
368 std::cerr << "Press Control-C again to abort." << std::endl; |
4787
|
369 |
4791
|
370 if (octave_interrupt_state >= 3) |
|
371 my_friendly_exit (sys_siglist[sig], sig, true); |
4787
|
372 } |
1
|
373 } |
|
374 |
2469
|
375 SIGHANDLER_RETURN (0); |
1
|
376 } |
|
377 |
4064
|
378 #ifdef SIGPIPE |
1
|
379 static RETSIGTYPE |
1488
|
380 sigpipe_handler (int /* sig */) |
1
|
381 { |
2626
|
382 MAYBE_ACK_SIGNAL (SIGPIPE); |
2554
|
383 |
|
384 MAYBE_REINSTALL_SIGHANDLER (SIGPIPE, sigpipe_handler); |
834
|
385 |
5142
|
386 octave_signal_caught = 1; |
|
387 |
|
388 octave_signals_caught[SIGPIPE] = true; |
1
|
389 |
1358
|
390 // Don't loop forever on account of this. |
|
391 |
5142
|
392 if (pipe_handler_error_count++ > 100 && octave_interrupt_state >= 0) |
4787
|
393 octave_interrupt_state++; |
1
|
394 |
2469
|
395 SIGHANDLER_RETURN (0); |
1
|
396 } |
4064
|
397 #endif /* defined(SIGPIPE) */ |
1
|
398 |
2705
|
399 octave_interrupt_handler |
2554
|
400 octave_catch_interrupts (void) |
|
401 { |
2705
|
402 octave_interrupt_handler retval; |
2554
|
403 |
|
404 #ifdef SIGINT |
2705
|
405 retval.int_handler = octave_set_signal_handler (SIGINT, sigint_handler); |
2554
|
406 #endif |
|
407 |
|
408 #ifdef SIGBREAK |
2705
|
409 retval.brk_handler = octave_set_signal_handler (SIGBREAK, sigint_handler); |
2554
|
410 #endif |
2705
|
411 |
|
412 return retval; |
2554
|
413 } |
|
414 |
2705
|
415 octave_interrupt_handler |
|
416 octave_ignore_interrupts (void) |
2554
|
417 { |
2705
|
418 octave_interrupt_handler retval; |
|
419 |
2554
|
420 #ifdef SIGINT |
2705
|
421 retval.int_handler = octave_set_signal_handler (SIGINT, SIG_IGN); |
2554
|
422 #endif |
|
423 |
|
424 #ifdef SIGBREAK |
2705
|
425 retval.brk_handler = octave_set_signal_handler (SIGBREAK, SIG_IGN); |
2554
|
426 #endif |
2705
|
427 |
|
428 return retval; |
|
429 } |
|
430 |
|
431 octave_interrupt_handler |
|
432 octave_set_interrupt_handler (const volatile octave_interrupt_handler& h) |
|
433 { |
|
434 octave_interrupt_handler retval; |
|
435 |
|
436 #ifdef SIGINT |
|
437 retval.int_handler = octave_set_signal_handler (SIGINT, h.int_handler); |
|
438 #endif |
|
439 |
|
440 #ifdef SIGBREAK |
|
441 retval.brk_handler = octave_set_signal_handler (SIGBREAK, h.brk_handler); |
|
442 #endif |
|
443 |
|
444 return retval; |
1651
|
445 } |
|
446 |
635
|
447 // Install all the handlers for the signals we might care about. |
|
448 |
1
|
449 void |
|
450 install_signal_handlers (void) |
|
451 { |
5142
|
452 for (int i = 0; i < NSIG; i++) |
|
453 octave_signals_caught[i] = false; |
|
454 |
2554
|
455 octave_catch_interrupts (); |
|
456 |
1
|
457 #ifdef SIGABRT |
1446
|
458 octave_set_signal_handler (SIGABRT, generic_sig_handler); |
1
|
459 #endif |
|
460 |
|
461 #ifdef SIGALRM |
1446
|
462 octave_set_signal_handler (SIGALRM, generic_sig_handler); |
1
|
463 #endif |
|
464 |
|
465 #ifdef SIGBUS |
1446
|
466 octave_set_signal_handler (SIGBUS, generic_sig_handler); |
1
|
467 #endif |
|
468 |
1230
|
469 #ifdef SIGCHLD |
1446
|
470 octave_set_signal_handler (SIGCHLD, sigchld_handler); |
1230
|
471 #endif |
|
472 |
3174
|
473 // SIGCLD |
|
474 // SIGCONT |
|
475 |
1
|
476 #ifdef SIGEMT |
1446
|
477 octave_set_signal_handler (SIGEMT, generic_sig_handler); |
1
|
478 #endif |
|
479 |
|
480 #ifdef SIGFPE |
1373
|
481 #if defined (__alpha__) |
1446
|
482 octave_set_signal_handler (SIGFPE, sigfpe_handler); |
1373
|
483 #else |
1446
|
484 octave_set_signal_handler (SIGFPE, generic_sig_handler); |
1
|
485 #endif |
1373
|
486 #endif |
1
|
487 |
|
488 #ifdef SIGHUP |
4449
|
489 octave_set_signal_handler (SIGHUP, sig_hup_or_term_handler); |
1
|
490 #endif |
|
491 |
|
492 #ifdef SIGILL |
1446
|
493 octave_set_signal_handler (SIGILL, generic_sig_handler); |
1
|
494 #endif |
|
495 |
3174
|
496 // SIGINFO |
|
497 // SIGINT |
|
498 |
1
|
499 #ifdef SIGIOT |
1446
|
500 octave_set_signal_handler (SIGIOT, generic_sig_handler); |
1
|
501 #endif |
|
502 |
|
503 #ifdef SIGLOST |
1446
|
504 octave_set_signal_handler (SIGLOST, generic_sig_handler); |
1
|
505 #endif |
|
506 |
|
507 #ifdef SIGPIPE |
1446
|
508 octave_set_signal_handler (SIGPIPE, sigpipe_handler); |
1
|
509 #endif |
|
510 |
|
511 #ifdef SIGPOLL |
1446
|
512 octave_set_signal_handler (SIGPOLL, SIG_IGN); |
1
|
513 #endif |
|
514 |
|
515 #ifdef SIGPROF |
1446
|
516 octave_set_signal_handler (SIGPROF, generic_sig_handler); |
1
|
517 #endif |
|
518 |
3174
|
519 // SIGPWR |
|
520 |
1
|
521 #ifdef SIGQUIT |
1446
|
522 octave_set_signal_handler (SIGQUIT, generic_sig_handler); |
1
|
523 #endif |
|
524 |
|
525 #ifdef SIGSEGV |
1446
|
526 octave_set_signal_handler (SIGSEGV, generic_sig_handler); |
1
|
527 #endif |
|
528 |
3174
|
529 // SIGSTOP |
|
530 |
1
|
531 #ifdef SIGSYS |
1446
|
532 octave_set_signal_handler (SIGSYS, generic_sig_handler); |
1
|
533 #endif |
|
534 |
|
535 #ifdef SIGTERM |
4449
|
536 octave_set_signal_handler (SIGTERM, sig_hup_or_term_handler); |
1
|
537 #endif |
|
538 |
|
539 #ifdef SIGTRAP |
1446
|
540 octave_set_signal_handler (SIGTRAP, generic_sig_handler); |
1
|
541 #endif |
|
542 |
3174
|
543 // SIGTSTP |
|
544 // SIGTTIN |
|
545 // SIGTTOU |
|
546 // SIGURG |
|
547 |
1
|
548 #ifdef SIGUSR1 |
1446
|
549 octave_set_signal_handler (SIGUSR1, generic_sig_handler); |
1
|
550 #endif |
|
551 |
|
552 #ifdef SIGUSR2 |
1446
|
553 octave_set_signal_handler (SIGUSR2, generic_sig_handler); |
1
|
554 #endif |
|
555 |
|
556 #ifdef SIGVTALRM |
1446
|
557 octave_set_signal_handler (SIGVTALRM, generic_sig_handler); |
1
|
558 #endif |
|
559 |
895
|
560 #ifdef SIGIO |
1446
|
561 octave_set_signal_handler (SIGIO, SIG_IGN); |
895
|
562 #endif |
|
563 |
3343
|
564 #if 0 |
3281
|
565 #ifdef SIGWINCH |
|
566 octave_set_signal_handler (SIGWINCH, sigwinch_handler); |
|
567 #endif |
3343
|
568 #endif |
3174
|
569 |
1
|
570 #ifdef SIGXCPU |
1446
|
571 octave_set_signal_handler (SIGXCPU, generic_sig_handler); |
1
|
572 #endif |
|
573 |
|
574 #ifdef SIGXFSZ |
1446
|
575 octave_set_signal_handler (SIGXFSZ, generic_sig_handler); |
1
|
576 #endif |
|
577 } |
|
578 |
4294
|
579 static Octave_map |
|
580 make_sig_struct (void) |
|
581 { |
|
582 Octave_map m; |
|
583 |
|
584 #ifdef SIGABRT |
4675
|
585 m.assign ("ABRT", SIGABRT); |
4294
|
586 #endif |
|
587 |
|
588 #ifdef SIGALRM |
4675
|
589 m.assign ("ALRM", SIGALRM); |
4294
|
590 #endif |
|
591 |
|
592 #ifdef SIGBUS |
4675
|
593 m.assign ("BUS", SIGBUS); |
4294
|
594 #endif |
|
595 |
|
596 #ifdef SIGCHLD |
4675
|
597 m.assign ("CHLD", SIGCHLD); |
4294
|
598 #endif |
|
599 |
|
600 #ifdef SIGCLD |
4675
|
601 m.assign ("CLD", SIGCLD); |
4294
|
602 #endif |
|
603 |
|
604 #ifdef SIGCONT |
4675
|
605 m.assign ("CONT", SIGCONT); |
4294
|
606 #endif |
|
607 |
|
608 #ifdef SIGEMT |
4675
|
609 m.assign ("EMT", SIGEMT); |
4294
|
610 #endif |
|
611 |
|
612 #ifdef SIGFPE |
4675
|
613 m.assign ("FPE", SIGFPE); |
4294
|
614 #endif |
|
615 |
|
616 #ifdef SIGHUP |
4675
|
617 m.assign ("HUP", SIGHUP); |
4294
|
618 #endif |
|
619 |
|
620 #ifdef SIGILL |
4675
|
621 m.assign ("ILL", SIGILL); |
4294
|
622 #endif |
|
623 |
|
624 #ifdef SIGINFO |
4675
|
625 m.assign ("INFO", SIGINFO); |
4294
|
626 #endif |
|
627 |
|
628 #ifdef SIGINT |
4675
|
629 m.assign ("INT", SIGINT); |
4294
|
630 #endif |
|
631 |
|
632 #ifdef SIGIOT |
4675
|
633 m.assign ("IOT", SIGIOT); |
4294
|
634 #endif |
|
635 |
|
636 #ifdef SIGLOST |
4675
|
637 m.assign ("LOST", SIGLOST); |
4294
|
638 #endif |
|
639 |
|
640 #ifdef SIGPIPE |
4675
|
641 m.assign ("PIPE", SIGPIPE); |
4294
|
642 #endif |
|
643 |
|
644 #ifdef SIGPOLL |
4675
|
645 m.assign ("POLL", SIGPOLL); |
4294
|
646 #endif |
|
647 |
|
648 #ifdef SIGPROF |
4675
|
649 m.assign ("PROF", SIGPROF); |
4294
|
650 #endif |
|
651 |
|
652 #ifdef SIGPWR |
4675
|
653 m.assign ("PWR", SIGPWR); |
4294
|
654 #endif |
|
655 |
|
656 #ifdef SIGQUIT |
4675
|
657 m.assign ("QUIT", SIGQUIT); |
4294
|
658 #endif |
|
659 |
|
660 #ifdef SIGSEGV |
4675
|
661 m.assign ("SEGV", SIGSEGV); |
4294
|
662 #endif |
|
663 |
|
664 #ifdef SIGSTOP |
4675
|
665 m.assign ("STOP", SIGSTOP); |
4294
|
666 #endif |
|
667 |
|
668 #ifdef SIGSYS |
4675
|
669 m.assign ("SYS", SIGSYS); |
4294
|
670 #endif |
|
671 |
|
672 #ifdef SIGTERM |
4675
|
673 m.assign ("TERM", SIGTERM); |
4294
|
674 #endif |
|
675 |
|
676 #ifdef SIGTRAP |
4675
|
677 m.assign ("TRAP", SIGTRAP); |
4294
|
678 #endif |
|
679 |
|
680 #ifdef SIGTSTP |
4675
|
681 m.assign ("TSTP", SIGTSTP); |
4294
|
682 #endif |
|
683 |
|
684 #ifdef SIGTTIN |
4675
|
685 m.assign ("TTIN", SIGTTIN); |
4294
|
686 #endif |
|
687 |
|
688 #ifdef SIGTTOU |
4675
|
689 m.assign ("TTOU", SIGTTOU); |
4294
|
690 #endif |
|
691 |
|
692 #ifdef SIGURG |
4675
|
693 m.assign ("URG", SIGURG); |
4294
|
694 #endif |
|
695 |
|
696 #ifdef SIGUSR1 |
4675
|
697 m.assign ("USR1", SIGUSR1); |
4294
|
698 #endif |
|
699 |
|
700 #ifdef SIGUSR2 |
4675
|
701 m.assign ("USR2", SIGUSR2); |
4294
|
702 #endif |
|
703 |
|
704 #ifdef SIGVTALRM |
4675
|
705 m.assign ("VTALRM", SIGVTALRM); |
4294
|
706 #endif |
|
707 |
|
708 #ifdef SIGIO |
4675
|
709 m.assign ("IO", SIGIO); |
4294
|
710 #endif |
|
711 |
|
712 #ifdef SIGWINCH |
4675
|
713 m.assign ("WINCH", SIGWINCH); |
4294
|
714 #endif |
|
715 |
|
716 #ifdef SIGXCPU |
4675
|
717 m.assign ("XCPU", SIGXCPU); |
4294
|
718 #endif |
|
719 |
|
720 #ifdef SIGXFSZ |
4675
|
721 m.assign ("XFSZ", SIGXFSZ); |
4294
|
722 #endif |
|
723 |
|
724 return m; |
|
725 } |
|
726 |
5142
|
727 octave_child_list::octave_child_list_rep *octave_child_list::instance = 0; |
5128
|
728 |
2926
|
729 bool |
|
730 octave_child_list::instance_ok (void) |
|
731 { |
|
732 bool retval = true; |
|
733 |
|
734 if (! instance) |
5142
|
735 instance = new octave_child_list_rep (); |
2926
|
736 |
|
737 if (! instance) |
|
738 { |
|
739 ::error ("unable to create child list object!"); |
|
740 |
|
741 retval = false; |
|
742 } |
|
743 |
|
744 return retval; |
|
745 } |
|
746 |
|
747 void |
5142
|
748 octave_child_list::insert (pid_t pid, octave_child::child_event_handler f) |
|
749 { |
|
750 if (instance_ok ()) |
|
751 instance->insert (pid, f); |
|
752 } |
|
753 |
|
754 void |
|
755 octave_child_list::reap (void) |
2926
|
756 { |
|
757 if (instance_ok ()) |
5142
|
758 instance->reap (); |
|
759 } |
|
760 |
|
761 bool |
|
762 octave_child_list::wait (void) |
|
763 { |
|
764 return (instance_ok ()) ? instance->wait () : false; |
2926
|
765 } |
|
766 |
5142
|
767 class pid_equal |
|
768 { |
|
769 public: |
|
770 |
|
771 pid_equal (pid_t v) : val (v) { } |
|
772 |
|
773 bool operator () (const octave_child& oc) const { return oc.pid == val; } |
|
774 |
|
775 private: |
|
776 |
|
777 pid_t val; |
|
778 }; |
|
779 |
2926
|
780 void |
|
781 octave_child_list::remove (pid_t pid) |
|
782 { |
|
783 if (instance_ok ()) |
5142
|
784 instance->remove_if (pid_equal (pid)); |
2926
|
785 } |
|
786 |
5142
|
787 #define OCL_REP octave_child_list::octave_child_list_rep |
2926
|
788 |
5142
|
789 void |
|
790 OCL_REP::insert (pid_t pid, octave_child::child_event_handler f) |
2926
|
791 { |
5142
|
792 append (octave_child (pid, f)); |
2926
|
793 } |
|
794 |
2209
|
795 void |
5142
|
796 OCL_REP::reap (void) |
2209
|
797 { |
5142
|
798 // Mark the record for PID invalid. |
2209
|
799 |
5142
|
800 for (iterator p = begin (); p != end (); p++) |
|
801 { |
|
802 // The call to the octave_child::child_event_handler might |
|
803 // invalidate the iterator (for example, by calling |
|
804 // octave_child_list::remove), so we increment the iterator |
|
805 // here. |
2209
|
806 |
5142
|
807 octave_child& oc = *p; |
2209
|
808 |
5142
|
809 if (oc.have_status) |
2209
|
810 { |
5142
|
811 oc.have_status = 0; |
|
812 |
|
813 octave_child::child_event_handler f = oc.handler; |
|
814 |
|
815 if (f && f (oc.pid, oc.status)) |
|
816 oc.pid = -1; |
2209
|
817 } |
|
818 } |
|
819 |
5142
|
820 remove_if (pid_equal (-1)); |
2209
|
821 } |
|
822 |
5142
|
823 // Wait on our children and record any changes in their status. |
|
824 |
|
825 bool |
|
826 OCL_REP::wait (void) |
2210
|
827 { |
5142
|
828 bool retval = false; |
2210
|
829 |
5142
|
830 for (iterator p = begin (); p != end (); p++) |
2210
|
831 { |
5142
|
832 octave_child& oc = *p; |
|
833 |
|
834 pid_t pid = oc.pid; |
|
835 |
|
836 if (pid > 0) |
|
837 { |
|
838 int status; |
2210
|
839 |
5142
|
840 if (waitpid (pid, &status, WNOHANG) > 0) |
|
841 { |
|
842 oc.have_status = 1; |
|
843 |
|
844 oc.status = status; |
|
845 |
|
846 retval = true; |
|
847 |
|
848 break; |
|
849 } |
2210
|
850 } |
|
851 } |
|
852 |
5142
|
853 return retval; |
2210
|
854 } |
|
855 |
4185
|
856 static int |
|
857 debug_on_interrupt (void) |
|
858 { |
|
859 Vdebug_on_interrupt = check_preference ("debug_on_interrupt"); |
|
860 |
|
861 return 0; |
|
862 } |
|
863 |
4449
|
864 static int |
|
865 sighup_dumps_octave_core (void) |
|
866 { |
|
867 Vsighup_dumps_octave_core = check_preference ("sighup_dumps_octave_core"); |
|
868 |
|
869 return 0; |
|
870 } |
|
871 |
|
872 static int |
|
873 sigterm_dumps_octave_core (void) |
|
874 { |
|
875 Vsigterm_dumps_octave_core = check_preference ("sigterm_dumps_octave_core"); |
|
876 |
|
877 return 0; |
|
878 } |
|
879 |
4185
|
880 void |
|
881 symbols_of_sighandlers (void) |
|
882 { |
4233
|
883 DEFVAR (debug_on_interrupt, false, debug_on_interrupt, |
4185
|
884 "-*- texinfo -*-\n\ |
|
885 @defvr {Built-in Variable} debug_on_interrupt\n\ |
|
886 If @code{debug_on_interrupt} is nonzero, Octave will try to enter\n\ |
|
887 debugging mode when it receives an interrupt signal (typically\n\ |
|
888 generated with @kbd{C-c}). If a second interrupt signal is received\n\ |
|
889 before reaching the debugging mode, a normal interrupt will occur.\n\ |
|
890 The default value is 0.\n\ |
|
891 @end defvr"); |
4294
|
892 |
4449
|
893 DEFVAR (sighup_dumps_octave_core, true, sighup_dumps_octave_core, |
|
894 "-*- texinfo -*-\n\ |
|
895 @defvr {Built-in Variable} sighup_dumps_octave_core\n\ |
|
896 If this variable is set to a nonzero value and\n\ |
|
897 @code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ |
|
898 current variables the the file \"octave-core\" if it receives a\n\ |
|
899 hangup signal. The default value is 1.\n\ |
|
900 @end defvr"); |
|
901 |
|
902 DEFVAR (sigterm_dumps_octave_core, true, sigterm_dumps_octave_core, |
|
903 "-*- texinfo -*-\n\ |
|
904 @defvr {Built-in Variable} sigterm_dumps_octave_core\n\ |
|
905 If this variable is set to a nonzero value and\n\ |
|
906 @code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ |
|
907 current variables the the file \"octave-core\" if it receives a\n\ |
|
908 terminate signal. The default value is 1.\n\ |
|
909 @end defvr"); |
|
910 |
4294
|
911 DEFCONST (SIG, make_sig_struct (), |
|
912 "-*- texinfo -*-\n\ |
|
913 @defvr {Built-in Variable} SIG\n\ |
|
914 Structure of Unix signal names and their defined values.\n\ |
|
915 @end defvr"); |
4185
|
916 } |
|
917 |
1
|
918 /* |
|
919 ;;; Local Variables: *** |
|
920 ;;; mode: C++ *** |
|
921 ;;; End: *** |
|
922 */ |