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) |
|
118 save_user_variables (); |
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 |
1373
|
240 if (can_interrupt) |
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) |
|
262 save_user_variables (); |
|
263 } |
|
264 break; |
|
265 #endif |
|
266 |
|
267 #if defined (SIGTERM) |
|
268 case SIGTERM: |
|
269 { |
|
270 if (Vsigterm_dumps_octave_core) |
|
271 save_user_variables (); |
|
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 { |
|
337 octave_interrupt_state++; |
|
338 |
|
339 if (interactive) |
|
340 { |
|
341 if (octave_interrupt_state > 3) |
|
342 { |
|
343 // XXX FIXME XXX -- might want to attempt to flush |
|
344 // any pending input first... |
|
345 |
|
346 std::cerr << "abort [y/N]? "; |
|
347 |
|
348 int c = octave_kbhit (); |
|
349 |
|
350 std::cerr << static_cast<char> (c) << std::endl; |
|
351 |
|
352 if (c == 'y' || c == 'Y') |
|
353 { |
|
354 std::cerr << "save top-level workspace [y/N]? "; |
|
355 |
|
356 c = octave_kbhit (); |
|
357 |
|
358 std::cerr << static_cast<char> (c) << std::endl; |
|
359 |
|
360 my_friendly_exit (sys_siglist[sig], sig, |
|
361 (c == 'y' || c == 'Y')); |
|
362 } |
|
363 else |
|
364 { |
|
365 // We will still eventually interrupt and jump to |
|
366 // the top level even if no additional interrupts |
|
367 // happen, but we will have to wait until it is |
|
368 // safe to do so. It will take 3 more |
|
369 // consecutive interrupts before we offer to |
|
370 // abort again. |
|
371 |
|
372 octave_interrupt_state = 1; |
|
373 } |
|
374 } |
|
375 } |
|
376 } |
1
|
377 } |
|
378 |
2469
|
379 SIGHANDLER_RETURN (0); |
1
|
380 } |
|
381 |
4064
|
382 #ifdef SIGPIPE |
1
|
383 static RETSIGTYPE |
1488
|
384 sigpipe_handler (int /* sig */) |
1
|
385 { |
2626
|
386 MAYBE_ACK_SIGNAL (SIGPIPE); |
2554
|
387 |
|
388 MAYBE_REINSTALL_SIGHANDLER (SIGPIPE, sigpipe_handler); |
834
|
389 |
1
|
390 if (pipe_handler_error_count++ == 0) |
3531
|
391 std::cerr << "warning: broken pipe\n"; |
1
|
392 |
1358
|
393 // Don't loop forever on account of this. |
|
394 |
4182
|
395 // XXX FIXME XXX -- will setting octave_interrupt_state really help |
|
396 // here? |
|
397 |
1
|
398 if (pipe_handler_error_count > 100) |
4787
|
399 octave_interrupt_state++; |
1
|
400 |
2469
|
401 SIGHANDLER_RETURN (0); |
1
|
402 } |
4064
|
403 #endif /* defined(SIGPIPE) */ |
1
|
404 |
2705
|
405 octave_interrupt_handler |
2554
|
406 octave_catch_interrupts (void) |
|
407 { |
2705
|
408 octave_interrupt_handler retval; |
2554
|
409 |
|
410 #ifdef SIGINT |
2705
|
411 retval.int_handler = octave_set_signal_handler (SIGINT, sigint_handler); |
2554
|
412 #endif |
|
413 |
|
414 #ifdef SIGBREAK |
2705
|
415 retval.brk_handler = octave_set_signal_handler (SIGBREAK, sigint_handler); |
2554
|
416 #endif |
2705
|
417 |
|
418 return retval; |
2554
|
419 } |
|
420 |
2705
|
421 octave_interrupt_handler |
|
422 octave_ignore_interrupts (void) |
2554
|
423 { |
2705
|
424 octave_interrupt_handler retval; |
|
425 |
2554
|
426 #ifdef SIGINT |
2705
|
427 retval.int_handler = octave_set_signal_handler (SIGINT, SIG_IGN); |
2554
|
428 #endif |
|
429 |
|
430 #ifdef SIGBREAK |
2705
|
431 retval.brk_handler = octave_set_signal_handler (SIGBREAK, SIG_IGN); |
2554
|
432 #endif |
2705
|
433 |
|
434 return retval; |
|
435 } |
|
436 |
|
437 octave_interrupt_handler |
|
438 octave_set_interrupt_handler (const volatile octave_interrupt_handler& h) |
|
439 { |
|
440 octave_interrupt_handler retval; |
|
441 |
|
442 #ifdef SIGINT |
|
443 retval.int_handler = octave_set_signal_handler (SIGINT, h.int_handler); |
|
444 #endif |
|
445 |
|
446 #ifdef SIGBREAK |
|
447 retval.brk_handler = octave_set_signal_handler (SIGBREAK, h.brk_handler); |
|
448 #endif |
|
449 |
|
450 return retval; |
1651
|
451 } |
|
452 |
635
|
453 // Install all the handlers for the signals we might care about. |
|
454 |
1
|
455 void |
|
456 install_signal_handlers (void) |
|
457 { |
2554
|
458 octave_catch_interrupts (); |
|
459 |
1
|
460 #ifdef SIGABRT |
1446
|
461 octave_set_signal_handler (SIGABRT, generic_sig_handler); |
1
|
462 #endif |
|
463 |
|
464 #ifdef SIGALRM |
1446
|
465 octave_set_signal_handler (SIGALRM, generic_sig_handler); |
1
|
466 #endif |
|
467 |
|
468 #ifdef SIGBUS |
1446
|
469 octave_set_signal_handler (SIGBUS, generic_sig_handler); |
1
|
470 #endif |
|
471 |
1230
|
472 #ifdef SIGCHLD |
1446
|
473 octave_set_signal_handler (SIGCHLD, sigchld_handler); |
1230
|
474 #endif |
|
475 |
3174
|
476 // SIGCLD |
|
477 // SIGCONT |
|
478 |
1
|
479 #ifdef SIGEMT |
1446
|
480 octave_set_signal_handler (SIGEMT, generic_sig_handler); |
1
|
481 #endif |
|
482 |
|
483 #ifdef SIGFPE |
1373
|
484 #if defined (__alpha__) |
1446
|
485 octave_set_signal_handler (SIGFPE, sigfpe_handler); |
1373
|
486 #else |
1446
|
487 octave_set_signal_handler (SIGFPE, generic_sig_handler); |
1
|
488 #endif |
1373
|
489 #endif |
1
|
490 |
|
491 #ifdef SIGHUP |
4449
|
492 octave_set_signal_handler (SIGHUP, sig_hup_or_term_handler); |
1
|
493 #endif |
|
494 |
|
495 #ifdef SIGILL |
1446
|
496 octave_set_signal_handler (SIGILL, generic_sig_handler); |
1
|
497 #endif |
|
498 |
3174
|
499 // SIGINFO |
|
500 // SIGINT |
|
501 |
1
|
502 #ifdef SIGIOT |
1446
|
503 octave_set_signal_handler (SIGIOT, generic_sig_handler); |
1
|
504 #endif |
|
505 |
|
506 #ifdef SIGLOST |
1446
|
507 octave_set_signal_handler (SIGLOST, generic_sig_handler); |
1
|
508 #endif |
|
509 |
|
510 #ifdef SIGPIPE |
1446
|
511 octave_set_signal_handler (SIGPIPE, sigpipe_handler); |
1
|
512 #endif |
|
513 |
|
514 #ifdef SIGPOLL |
1446
|
515 octave_set_signal_handler (SIGPOLL, SIG_IGN); |
1
|
516 #endif |
|
517 |
|
518 #ifdef SIGPROF |
1446
|
519 octave_set_signal_handler (SIGPROF, generic_sig_handler); |
1
|
520 #endif |
|
521 |
3174
|
522 // SIGPWR |
|
523 |
1
|
524 #ifdef SIGQUIT |
1446
|
525 octave_set_signal_handler (SIGQUIT, generic_sig_handler); |
1
|
526 #endif |
|
527 |
|
528 #ifdef SIGSEGV |
1446
|
529 octave_set_signal_handler (SIGSEGV, generic_sig_handler); |
1
|
530 #endif |
|
531 |
3174
|
532 // SIGSTOP |
|
533 |
1
|
534 #ifdef SIGSYS |
1446
|
535 octave_set_signal_handler (SIGSYS, generic_sig_handler); |
1
|
536 #endif |
|
537 |
|
538 #ifdef SIGTERM |
4449
|
539 octave_set_signal_handler (SIGTERM, sig_hup_or_term_handler); |
1
|
540 #endif |
|
541 |
|
542 #ifdef SIGTRAP |
1446
|
543 octave_set_signal_handler (SIGTRAP, generic_sig_handler); |
1
|
544 #endif |
|
545 |
3174
|
546 // SIGTSTP |
|
547 // SIGTTIN |
|
548 // SIGTTOU |
|
549 // SIGURG |
|
550 |
1
|
551 #ifdef SIGUSR1 |
1446
|
552 octave_set_signal_handler (SIGUSR1, generic_sig_handler); |
1
|
553 #endif |
|
554 |
|
555 #ifdef SIGUSR2 |
1446
|
556 octave_set_signal_handler (SIGUSR2, generic_sig_handler); |
1
|
557 #endif |
|
558 |
|
559 #ifdef SIGVTALRM |
1446
|
560 octave_set_signal_handler (SIGVTALRM, generic_sig_handler); |
1
|
561 #endif |
|
562 |
895
|
563 #ifdef SIGIO |
1446
|
564 octave_set_signal_handler (SIGIO, SIG_IGN); |
895
|
565 #endif |
|
566 |
3343
|
567 #if 0 |
3281
|
568 #ifdef SIGWINCH |
|
569 octave_set_signal_handler (SIGWINCH, sigwinch_handler); |
|
570 #endif |
3343
|
571 #endif |
3174
|
572 |
1
|
573 #ifdef SIGXCPU |
1446
|
574 octave_set_signal_handler (SIGXCPU, generic_sig_handler); |
1
|
575 #endif |
|
576 |
|
577 #ifdef SIGXFSZ |
1446
|
578 octave_set_signal_handler (SIGXFSZ, generic_sig_handler); |
1
|
579 #endif |
|
580 } |
|
581 |
4294
|
582 static Octave_map |
|
583 make_sig_struct (void) |
|
584 { |
|
585 Octave_map m; |
|
586 |
|
587 #ifdef SIGABRT |
4675
|
588 m.assign ("ABRT", SIGABRT); |
4294
|
589 #endif |
|
590 |
|
591 #ifdef SIGALRM |
4675
|
592 m.assign ("ALRM", SIGALRM); |
4294
|
593 #endif |
|
594 |
|
595 #ifdef SIGBUS |
4675
|
596 m.assign ("BUS", SIGBUS); |
4294
|
597 #endif |
|
598 |
|
599 #ifdef SIGCHLD |
4675
|
600 m.assign ("CHLD", SIGCHLD); |
4294
|
601 #endif |
|
602 |
|
603 #ifdef SIGCLD |
4675
|
604 m.assign ("CLD", SIGCLD); |
4294
|
605 #endif |
|
606 |
|
607 #ifdef SIGCONT |
4675
|
608 m.assign ("CONT", SIGCONT); |
4294
|
609 #endif |
|
610 |
|
611 #ifdef SIGEMT |
4675
|
612 m.assign ("EMT", SIGEMT); |
4294
|
613 #endif |
|
614 |
|
615 #ifdef SIGFPE |
4675
|
616 m.assign ("FPE", SIGFPE); |
4294
|
617 #endif |
|
618 |
|
619 #ifdef SIGHUP |
4675
|
620 m.assign ("HUP", SIGHUP); |
4294
|
621 #endif |
|
622 |
|
623 #ifdef SIGILL |
4675
|
624 m.assign ("ILL", SIGILL); |
4294
|
625 #endif |
|
626 |
|
627 #ifdef SIGINFO |
4675
|
628 m.assign ("INFO", SIGINFO); |
4294
|
629 #endif |
|
630 |
|
631 #ifdef SIGINT |
4675
|
632 m.assign ("INT", SIGINT); |
4294
|
633 #endif |
|
634 |
|
635 #ifdef SIGIOT |
4675
|
636 m.assign ("IOT", SIGIOT); |
4294
|
637 #endif |
|
638 |
|
639 #ifdef SIGLOST |
4675
|
640 m.assign ("LOST", SIGLOST); |
4294
|
641 #endif |
|
642 |
|
643 #ifdef SIGPIPE |
4675
|
644 m.assign ("PIPE", SIGPIPE); |
4294
|
645 #endif |
|
646 |
|
647 #ifdef SIGPOLL |
4675
|
648 m.assign ("POLL", SIGPOLL); |
4294
|
649 #endif |
|
650 |
|
651 #ifdef SIGPROF |
4675
|
652 m.assign ("PROF", SIGPROF); |
4294
|
653 #endif |
|
654 |
|
655 #ifdef SIGPWR |
4675
|
656 m.assign ("PWR", SIGPWR); |
4294
|
657 #endif |
|
658 |
|
659 #ifdef SIGQUIT |
4675
|
660 m.assign ("QUIT", SIGQUIT); |
4294
|
661 #endif |
|
662 |
|
663 #ifdef SIGSEGV |
4675
|
664 m.assign ("SEGV", SIGSEGV); |
4294
|
665 #endif |
|
666 |
|
667 #ifdef SIGSTOP |
4675
|
668 m.assign ("STOP", SIGSTOP); |
4294
|
669 #endif |
|
670 |
|
671 #ifdef SIGSYS |
4675
|
672 m.assign ("SYS", SIGSYS); |
4294
|
673 #endif |
|
674 |
|
675 #ifdef SIGTERM |
4675
|
676 m.assign ("TERM", SIGTERM); |
4294
|
677 #endif |
|
678 |
|
679 #ifdef SIGTRAP |
4675
|
680 m.assign ("TRAP", SIGTRAP); |
4294
|
681 #endif |
|
682 |
|
683 #ifdef SIGTSTP |
4675
|
684 m.assign ("TSTP", SIGTSTP); |
4294
|
685 #endif |
|
686 |
|
687 #ifdef SIGTTIN |
4675
|
688 m.assign ("TTIN", SIGTTIN); |
4294
|
689 #endif |
|
690 |
|
691 #ifdef SIGTTOU |
4675
|
692 m.assign ("TTOU", SIGTTOU); |
4294
|
693 #endif |
|
694 |
|
695 #ifdef SIGURG |
4675
|
696 m.assign ("URG", SIGURG); |
4294
|
697 #endif |
|
698 |
|
699 #ifdef SIGUSR1 |
4675
|
700 m.assign ("USR1", SIGUSR1); |
4294
|
701 #endif |
|
702 |
|
703 #ifdef SIGUSR2 |
4675
|
704 m.assign ("USR2", SIGUSR2); |
4294
|
705 #endif |
|
706 |
|
707 #ifdef SIGVTALRM |
4675
|
708 m.assign ("VTALRM", SIGVTALRM); |
4294
|
709 #endif |
|
710 |
|
711 #ifdef SIGIO |
4675
|
712 m.assign ("IO", SIGIO); |
4294
|
713 #endif |
|
714 |
|
715 #ifdef SIGWINCH |
4675
|
716 m.assign ("WINCH", SIGWINCH); |
4294
|
717 #endif |
|
718 |
|
719 #ifdef SIGXCPU |
4675
|
720 m.assign ("XCPU", SIGXCPU); |
4294
|
721 #endif |
|
722 |
|
723 #ifdef SIGXFSZ |
4675
|
724 m.assign ("XFSZ", SIGXFSZ); |
4294
|
725 #endif |
|
726 |
|
727 return m; |
|
728 } |
|
729 |
2209
|
730 octave_child_list *octave_child_list::instance = 0; |
|
731 |
2926
|
732 bool |
|
733 octave_child_list::instance_ok (void) |
|
734 { |
|
735 bool retval = true; |
|
736 |
|
737 if (! instance) |
|
738 instance = new octave_child_list (); |
|
739 |
|
740 if (! instance) |
|
741 { |
|
742 ::error ("unable to create child list object!"); |
|
743 |
|
744 retval = false; |
|
745 } |
|
746 |
|
747 return retval; |
|
748 } |
|
749 |
|
750 void |
|
751 octave_child_list::insert (pid_t pid, octave_child::dead_child_handler f) |
|
752 { |
|
753 if (instance_ok ()) |
|
754 instance->do_insert (pid, f); |
|
755 } |
|
756 |
|
757 void |
|
758 octave_child_list::remove (pid_t pid) |
|
759 { |
|
760 if (instance_ok ()) |
|
761 instance->do_remove (pid); |
|
762 } |
|
763 |
|
764 int |
|
765 octave_child_list::length (void) |
|
766 { |
|
767 return (instance_ok ()) ? instance->do_length () : 0; |
|
768 } |
|
769 |
|
770 octave_child& |
|
771 octave_child_list::elem (int i) |
|
772 { |
|
773 static octave_child foo; |
|
774 |
|
775 return (instance_ok ()) ? instance->do_elem (i) : foo; |
|
776 } |
|
777 |
2209
|
778 void |
|
779 octave_child_list::do_insert (pid_t pid, octave_child::dead_child_handler f) |
|
780 { |
|
781 // Insert item in first open slot, increasing size of list if |
|
782 // necessary. |
|
783 |
|
784 bool enlarge = true; |
|
785 |
|
786 for (int i = 0; i < curr_len; i++) |
|
787 { |
2305
|
788 octave_child& tmp = list (i); |
2209
|
789 |
|
790 if (tmp.pid < 0) |
|
791 { |
2305
|
792 list (i) = octave_child (pid, f); |
2209
|
793 enlarge = false; |
|
794 break; |
|
795 } |
|
796 } |
|
797 |
|
798 if (enlarge) |
|
799 { |
|
800 int total_len = list.length (); |
|
801 |
|
802 if (curr_len == total_len) |
|
803 { |
|
804 if (total_len == 0) |
|
805 list.resize (16); |
|
806 else |
|
807 list.resize (total_len * 2); |
|
808 } |
|
809 |
2305
|
810 list (curr_len) = octave_child (pid, f); |
2209
|
811 curr_len++; |
|
812 } |
|
813 } |
|
814 |
|
815 void |
2210
|
816 octave_child_list::do_remove (pid_t pid) |
|
817 { |
|
818 // Mark the record for PID invalid. |
|
819 |
|
820 for (int i = 0; i < curr_len; i++) |
|
821 { |
2305
|
822 octave_child& tmp = list (i); |
2210
|
823 |
|
824 if (tmp.pid == pid) |
|
825 { |
|
826 tmp.pid = -1; |
|
827 break; |
|
828 } |
|
829 } |
|
830 } |
|
831 |
2926
|
832 int |
|
833 octave_child_list::do_length (void) const |
|
834 { |
|
835 return curr_len; |
|
836 } |
|
837 |
|
838 octave_child& |
|
839 octave_child_list::do_elem (int i) |
2210
|
840 { |
2926
|
841 static octave_child foo; |
|
842 |
|
843 int n = do_length (); |
2210
|
844 |
2926
|
845 if (i >= 0 && i < n) |
|
846 return list (i); |
2210
|
847 else |
2926
|
848 return foo; |
2210
|
849 } |
|
850 |
4185
|
851 static int |
|
852 debug_on_interrupt (void) |
|
853 { |
|
854 Vdebug_on_interrupt = check_preference ("debug_on_interrupt"); |
|
855 |
|
856 return 0; |
|
857 } |
|
858 |
4449
|
859 static int |
|
860 sighup_dumps_octave_core (void) |
|
861 { |
|
862 Vsighup_dumps_octave_core = check_preference ("sighup_dumps_octave_core"); |
|
863 |
|
864 return 0; |
|
865 } |
|
866 |
|
867 static int |
|
868 sigterm_dumps_octave_core (void) |
|
869 { |
|
870 Vsigterm_dumps_octave_core = check_preference ("sigterm_dumps_octave_core"); |
|
871 |
|
872 return 0; |
|
873 } |
|
874 |
4185
|
875 void |
|
876 symbols_of_sighandlers (void) |
|
877 { |
4233
|
878 DEFVAR (debug_on_interrupt, false, debug_on_interrupt, |
4185
|
879 "-*- texinfo -*-\n\ |
|
880 @defvr {Built-in Variable} debug_on_interrupt\n\ |
|
881 If @code{debug_on_interrupt} is nonzero, Octave will try to enter\n\ |
|
882 debugging mode when it receives an interrupt signal (typically\n\ |
|
883 generated with @kbd{C-c}). If a second interrupt signal is received\n\ |
|
884 before reaching the debugging mode, a normal interrupt will occur.\n\ |
|
885 The default value is 0.\n\ |
|
886 @end defvr"); |
4294
|
887 |
4449
|
888 DEFVAR (sighup_dumps_octave_core, true, sighup_dumps_octave_core, |
|
889 "-*- texinfo -*-\n\ |
|
890 @defvr {Built-in Variable} sighup_dumps_octave_core\n\ |
|
891 If this variable is set to a nonzero value and\n\ |
|
892 @code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ |
|
893 current variables the the file \"octave-core\" if it receives a\n\ |
|
894 hangup signal. The default value is 1.\n\ |
|
895 @end defvr"); |
|
896 |
|
897 DEFVAR (sigterm_dumps_octave_core, true, sigterm_dumps_octave_core, |
|
898 "-*- texinfo -*-\n\ |
|
899 @defvr {Built-in Variable} sigterm_dumps_octave_core\n\ |
|
900 If this variable is set to a nonzero value and\n\ |
|
901 @code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ |
|
902 current variables the the file \"octave-core\" if it receives a\n\ |
|
903 terminate signal. The default value is 1.\n\ |
|
904 @end defvr"); |
|
905 |
4294
|
906 DEFCONST (SIG, make_sig_struct (), |
|
907 "-*- texinfo -*-\n\ |
|
908 @defvr {Built-in Variable} SIG\n\ |
|
909 Structure of Unix signal names and their defined values.\n\ |
|
910 @end defvr"); |
4185
|
911 } |
|
912 |
1
|
913 /* |
|
914 ;;; Local Variables: *** |
|
915 ;;; mode: C++ *** |
|
916 ;;; End: *** |
|
917 */ |