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