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