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