1
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 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> |
1343
|
28 #include <csignal> |
2536
|
29 |
1344
|
30 #include <new> |
|
31 |
1350
|
32 #include <iostream.h> |
|
33 |
|
34 #ifdef HAVE_UNISTD_H |
2442
|
35 #ifdef HAVE_SYS_TYPES_H |
834
|
36 #include <sys/types.h> |
2442
|
37 #endif |
834
|
38 #include <unistd.h> |
|
39 #endif |
1343
|
40 |
1352
|
41 #include "error.h" |
1373
|
42 #include "load-save.h" |
2091
|
43 #include "pager.h" |
1
|
44 #include "sighandlers.h" |
1352
|
45 #include "syswait.h" |
2091
|
46 #include "toplev.h" |
1
|
47 #include "utils.h" |
|
48 |
|
49 // Nonzero means we have already printed a message for this series of |
|
50 // SIGPIPES. We assume that the writer will eventually give up. |
|
51 int pipe_handler_error_count = 0; |
|
52 |
|
53 // Nonzero means we can be interrupted. |
|
54 int can_interrupt = 0; |
|
55 |
2016
|
56 // Allow us to save the signal mask and then restore it to the most |
|
57 // recently saved value. This is necessary when using the POSIX |
|
58 // signal handling interface on some systems calling longjmp out of |
|
59 // the signal handler to get to the top level on an interrupt doesn't |
|
60 // restore the original signal mask. Alternatively, we could use |
|
61 // sigsetjmp/siglongjmp, but saving and restoring the signal mask |
|
62 // ourselves works ok and seems simpler just now. |
|
63 |
|
64 #if defined (HAVE_POSIX_SIGNALS) |
|
65 static sigset_t octave_signal_mask; |
|
66 #endif |
|
67 |
2469
|
68 #if RETSIGTYPE == void |
|
69 #define SIGHANDLER_RETURN(status) return |
|
70 #else |
|
71 #define SIGHANDLER_RETURN(status) return status |
|
72 #endif |
|
73 |
2554
|
74 #if defined (MUST_REINSTALL_SIGHANDLERS) |
|
75 #define MAYBE_REINSTALL_SIGHANDLER(sig, handler) \ |
|
76 octave_set_signal_handler (sig, handler) |
|
77 #else |
|
78 #define MAYBE_REINSTALL_SIGHANDLER(sig, handler) \ |
|
79 do { } while (0) |
|
80 #endif |
|
81 |
|
82 #if defined (__EMX__) |
2626
|
83 #define MAYBE_ACK_SIGNAL(sig) \ |
2554
|
84 octave_set_signal_handler (sig, SIG_ACK) |
|
85 #else |
2626
|
86 #define MAYBE_ACK_SIGNAL(sig) \ |
2554
|
87 do { } while (0) |
|
88 #endif |
|
89 |
2016
|
90 void |
|
91 octave_save_signal_mask (void) |
|
92 { |
|
93 #if defined (HAVE_POSIX_SIGNALS) |
|
94 sigprocmask (0, 0, &octave_signal_mask); |
|
95 #endif |
|
96 } |
|
97 |
|
98 void |
|
99 octave_restore_signal_mask (void) |
|
100 { |
|
101 #if defined (HAVE_POSIX_SIGNALS) |
|
102 sigprocmask (SIG_SETMASK, &octave_signal_mask, 0); |
|
103 #endif |
|
104 } |
|
105 |
2554
|
106 struct |
|
107 octave_interrupt_handler |
|
108 { |
|
109 #ifdef SIGINT |
|
110 sig_handler *int_handler; |
|
111 #endif |
|
112 |
|
113 #ifdef SIGBREAK |
|
114 sig_handler *brk_handler; |
|
115 #endif |
|
116 }; |
|
117 |
|
118 static octave_interrupt_handler the_interrupt_handler; |
|
119 |
1
|
120 static void |
|
121 my_friendly_exit (const char *sig_name, int sig_number) |
|
122 { |
2536
|
123 static bool been_there_done_that = false; |
|
124 |
|
125 if (been_there_done_that) |
|
126 { |
2554
|
127 #if defined (SIGABRT) |
2536
|
128 octave_set_signal_handler (SIGABRT, SIG_DFL); |
|
129 #endif |
|
130 |
|
131 error ("attempted clean up seems to have failed -- aborting..."); |
1373
|
132 |
2536
|
133 abort (); |
|
134 } |
|
135 else |
|
136 { |
|
137 been_there_done_that = true; |
1373
|
138 |
2536
|
139 error ("%s -- stopping myself...", sig_name); |
|
140 |
|
141 save_user_variables (); |
|
142 |
|
143 clean_up_and_exit (sig_number); |
|
144 } |
1
|
145 } |
|
146 |
635
|
147 // I know, not really a signal handler. |
|
148 |
|
149 static void |
|
150 octave_new_handler (void) |
|
151 { |
1394
|
152 error ("memory exhausted -- trying to return to prompt"); |
|
153 |
|
154 if (can_interrupt) |
|
155 { |
|
156 jump_to_top_level (); |
|
157 panic_impossible (); |
|
158 } |
|
159 else |
1395
|
160 my_friendly_exit ("operator new", 1); |
635
|
161 } |
|
162 |
1446
|
163 sig_handler * |
|
164 octave_set_signal_handler (int sig, sig_handler *handler) |
|
165 { |
|
166 #if defined (HAVE_POSIX_SIGNALS) |
|
167 struct sigaction act, oact; |
|
168 act.sa_handler = handler; |
|
169 act.sa_flags = 0; |
|
170 sigemptyset (&act.sa_mask); |
|
171 sigemptyset (&oact.sa_mask); |
|
172 sigaction (sig, &act, &oact); |
|
173 return oact.sa_handler; |
|
174 #else |
|
175 return signal (sig, handler); |
|
176 #endif |
|
177 } |
|
178 |
1
|
179 static RETSIGTYPE |
1446
|
180 generic_sig_handler (int sig) |
1
|
181 { |
1446
|
182 my_friendly_exit (sys_siglist[sig], sig); |
1
|
183 |
2469
|
184 SIGHANDLER_RETURN (0); |
1
|
185 } |
|
186 |
2091
|
187 // Handle SIGCHLD. |
1230
|
188 |
|
189 static RETSIGTYPE |
2092
|
190 sigchld_handler (int /* sig */) |
1230
|
191 { |
2554
|
192 volatile octave_interrupt_handler *saved_interrupt_handler |
|
193 = octave_ignore_interrupts (); |
|
194 |
2626
|
195 // I wonder if this is really right, or if SIGCHLD should just be |
|
196 // blocked on OS/2 systems the same as for systems with POSIX signal |
|
197 // functions. |
|
198 |
|
199 #if defined (__EMX__) |
2554
|
200 volatile sig_handler *saved_sigchld_handler |
2626
|
201 = octave_set_signal_handler (SIGCHLD, SIG_IGN); |
2554
|
202 #endif |
|
203 |
2626
|
204 sigset_t set, oset; |
|
205 |
|
206 BLOCK_CHILD (set, oset); |
|
207 |
2209
|
208 int n = octave_child_list::length (); |
|
209 |
2554
|
210 if (n == 0) |
1230
|
211 { |
2554
|
212 waitpid (-1, 0, WNOHANG); |
|
213 } |
|
214 else |
|
215 { |
|
216 for (int i = 0; i < n; i++) |
|
217 { |
|
218 octave_child& elt = octave_child_list::elem (i); |
2209
|
219 |
2554
|
220 pid_t pid = elt.pid; |
2209
|
221 |
2554
|
222 if (pid > 0) |
2091
|
223 { |
2554
|
224 int status; |
|
225 |
|
226 if (waitpid (pid, &status, WNOHANG) > 0) |
|
227 { |
|
228 elt.pid = -1; |
2197
|
229 |
2554
|
230 octave_child::dead_child_handler f = elt.handler; |
2197
|
231 |
2554
|
232 if (f) |
|
233 f (pid, status); |
2209
|
234 |
2554
|
235 break; |
|
236 } |
2091
|
237 } |
1230
|
238 } |
|
239 } |
2469
|
240 |
2600
|
241 octave_set_interrupt_handler (saved_interrupt_handler); |
2554
|
242 |
2626
|
243 UNBLOCK_CHILD (oset); |
|
244 |
|
245 #ifdef __EMX__ |
2554
|
246 octave_set_signal_handler (SIGCHLD, saved_sigchld_handler); |
2475
|
247 #endif |
|
248 |
2626
|
249 MAYBE_ACK_SIGNAL (SIGCHLD); |
2554
|
250 |
|
251 MAYBE_REINSTALL_SIGHANDLER (SIGCHLD, sigchld_handler); |
|
252 |
2469
|
253 SIGHANDLER_RETURN (0); |
1230
|
254 } |
|
255 |
1373
|
256 #if defined (__alpha__) |
|
257 static RETSIGTYPE |
1488
|
258 sigfpe_handler (int /* sig */) |
1373
|
259 { |
2626
|
260 MAYBE_ACK_SIGNAL (SIGFPE); |
2554
|
261 |
|
262 MAYBE_REINSTALL_SIGHANDLER (SIGFPE, sigfpe_handler); |
1373
|
263 |
1394
|
264 error ("floating point exception -- trying to return to prompt"); |
1373
|
265 |
|
266 if (can_interrupt) |
|
267 { |
|
268 jump_to_top_level (); |
|
269 panic_impossible (); |
|
270 } |
|
271 |
2469
|
272 SIGHANDLER_RETURN (0); |
1373
|
273 } |
|
274 #endif |
|
275 |
635
|
276 // Handle SIGINT by restarting the parser (see octave.cc). |
2554
|
277 // |
|
278 // This also has to work for SIGBREAK (on systems that have it), so we |
|
279 // use the value of sig, instead of just assuming that it is called |
|
280 // for SIGINT only. |
635
|
281 |
1
|
282 static RETSIGTYPE |
2554
|
283 sigint_handler (int sig) |
1
|
284 { |
2626
|
285 MAYBE_ACK_SIGNAL (sig); |
2554
|
286 |
|
287 MAYBE_REINSTALL_SIGHANDLER (sig, sigint_handler); |
834
|
288 |
1
|
289 if (can_interrupt) |
|
290 { |
|
291 jump_to_top_level (); |
|
292 panic_impossible (); |
|
293 } |
|
294 |
2469
|
295 SIGHANDLER_RETURN (0); |
1
|
296 } |
|
297 |
|
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) |
2206
|
306 warning ("broken pipe"); |
1
|
307 |
1358
|
308 // Don't loop forever on account of this. |
|
309 |
1
|
310 if (pipe_handler_error_count > 100) |
|
311 jump_to_top_level (); |
|
312 |
2469
|
313 SIGHANDLER_RETURN (0); |
1
|
314 } |
|
315 |
1651
|
316 void |
2554
|
317 octave_catch_interrupts (void) |
|
318 { |
|
319 #ifdef SIGINT |
|
320 octave_set_signal_handler (SIGINT, sigint_handler); |
|
321 |
|
322 the_interrupt_handler.int_handler = sigint_handler; |
|
323 #endif |
|
324 |
|
325 #ifdef SIGBREAK |
|
326 octave_set_signal_handler (SIGBREAK, sigint_handler); |
|
327 |
|
328 the_interrupt_handler.brk_handler = sigint_handler; |
|
329 #endif |
|
330 } |
|
331 |
|
332 octave_interrupt_handler * |
|
333 octave_ignore_interrupts (void) |
1651
|
334 { |
2554
|
335 #ifdef SIGINT |
|
336 the_interrupt_handler.int_handler |
|
337 = octave_set_signal_handler (SIGINT, SIG_IGN); |
|
338 #endif |
|
339 |
|
340 #ifdef SIGBREAK |
|
341 the_interrupt_handler.int_handler |
|
342 = octave_set_signal_handler (SIGBREAK, SIG_IGN); |
|
343 #endif |
|
344 |
|
345 return &the_interrupt_handler; |
|
346 } |
|
347 |
|
348 octave_interrupt_handler * |
|
349 octave_set_interrupt_handler (const volatile octave_interrupt_handler *h) |
|
350 { |
|
351 if (h) |
|
352 { |
|
353 #ifdef SIGINT |
|
354 the_interrupt_handler.int_handler |
|
355 = octave_set_signal_handler (SIGINT, h->int_handler); |
|
356 #endif |
|
357 |
|
358 #ifdef SIGBREAK |
|
359 the_interrupt_handler.int_handler |
|
360 = octave_set_signal_handler (SIGBREAK, h->brk_handler); |
|
361 #endif |
|
362 } |
|
363 |
|
364 return &the_interrupt_handler; |
1651
|
365 } |
|
366 |
635
|
367 // Install all the handlers for the signals we might care about. |
|
368 |
1
|
369 void |
|
370 install_signal_handlers (void) |
|
371 { |
635
|
372 set_new_handler (octave_new_handler); |
|
373 |
2554
|
374 octave_catch_interrupts (); |
|
375 |
1
|
376 #ifdef SIGABRT |
1446
|
377 octave_set_signal_handler (SIGABRT, generic_sig_handler); |
1
|
378 #endif |
|
379 |
|
380 #ifdef SIGALRM |
1446
|
381 octave_set_signal_handler (SIGALRM, generic_sig_handler); |
1
|
382 #endif |
|
383 |
|
384 #ifdef SIGBUS |
1446
|
385 octave_set_signal_handler (SIGBUS, generic_sig_handler); |
1
|
386 #endif |
|
387 |
1230
|
388 #ifdef SIGCHLD |
1446
|
389 octave_set_signal_handler (SIGCHLD, sigchld_handler); |
1230
|
390 #endif |
|
391 |
1
|
392 #ifdef SIGEMT |
1446
|
393 octave_set_signal_handler (SIGEMT, generic_sig_handler); |
1
|
394 #endif |
|
395 |
|
396 #ifdef SIGFPE |
1373
|
397 #if defined (__alpha__) |
1446
|
398 octave_set_signal_handler (SIGFPE, sigfpe_handler); |
1373
|
399 #else |
1446
|
400 octave_set_signal_handler (SIGFPE, generic_sig_handler); |
1
|
401 #endif |
1373
|
402 #endif |
1
|
403 |
|
404 #ifdef SIGHUP |
1446
|
405 octave_set_signal_handler (SIGHUP, generic_sig_handler); |
1
|
406 #endif |
|
407 |
|
408 #ifdef SIGILL |
1446
|
409 octave_set_signal_handler (SIGILL, generic_sig_handler); |
1
|
410 #endif |
|
411 |
|
412 #ifdef SIGIOT |
1446
|
413 octave_set_signal_handler (SIGIOT, generic_sig_handler); |
1
|
414 #endif |
|
415 |
|
416 #ifdef SIGLOST |
1446
|
417 octave_set_signal_handler (SIGLOST, generic_sig_handler); |
1
|
418 #endif |
|
419 |
|
420 #ifdef SIGPIPE |
1446
|
421 octave_set_signal_handler (SIGPIPE, sigpipe_handler); |
1
|
422 #endif |
|
423 |
|
424 #ifdef SIGPOLL |
1446
|
425 octave_set_signal_handler (SIGPOLL, SIG_IGN); |
1
|
426 #endif |
|
427 |
|
428 #ifdef SIGPROF |
1446
|
429 octave_set_signal_handler (SIGPROF, generic_sig_handler); |
1
|
430 #endif |
|
431 |
|
432 #ifdef SIGQUIT |
1446
|
433 octave_set_signal_handler (SIGQUIT, generic_sig_handler); |
1
|
434 #endif |
|
435 |
|
436 #ifdef SIGSEGV |
1446
|
437 octave_set_signal_handler (SIGSEGV, generic_sig_handler); |
1
|
438 #endif |
|
439 |
|
440 #ifdef SIGSYS |
1446
|
441 octave_set_signal_handler (SIGSYS, generic_sig_handler); |
1
|
442 #endif |
|
443 |
|
444 #ifdef SIGTERM |
1446
|
445 octave_set_signal_handler (SIGTERM, generic_sig_handler); |
1
|
446 #endif |
|
447 |
|
448 #ifdef SIGTRAP |
1446
|
449 octave_set_signal_handler (SIGTRAP, generic_sig_handler); |
1
|
450 #endif |
|
451 |
|
452 #ifdef SIGUSR1 |
1446
|
453 octave_set_signal_handler (SIGUSR1, generic_sig_handler); |
1
|
454 #endif |
|
455 |
|
456 #ifdef SIGUSR2 |
1446
|
457 octave_set_signal_handler (SIGUSR2, generic_sig_handler); |
1
|
458 #endif |
|
459 |
|
460 #ifdef SIGVTALRM |
1446
|
461 octave_set_signal_handler (SIGVTALRM, generic_sig_handler); |
1
|
462 #endif |
|
463 |
895
|
464 #ifdef SIGIO |
1446
|
465 octave_set_signal_handler (SIGIO, SIG_IGN); |
895
|
466 #endif |
|
467 |
1
|
468 #ifdef SIGXCPU |
1446
|
469 octave_set_signal_handler (SIGXCPU, generic_sig_handler); |
1
|
470 #endif |
|
471 |
|
472 #ifdef SIGXFSZ |
1446
|
473 octave_set_signal_handler (SIGXFSZ, generic_sig_handler); |
1
|
474 #endif |
|
475 } |
|
476 |
886
|
477 #ifndef HAVE_SYS_SIGLIST |
839
|
478 char *sys_siglist[NSIG + 1] = |
|
479 { |
|
480 #ifdef AIX |
|
481 /* AIX has changed the signals a bit */ |
|
482 "bogus signal", /* 0 */ |
|
483 "hangup", /* 1 SIGHUP */ |
|
484 "interrupt", /* 2 SIGINT */ |
|
485 "quit", /* 3 SIGQUIT */ |
|
486 "illegal instruction", /* 4 SIGILL */ |
|
487 "trace trap", /* 5 SIGTRAP */ |
|
488 "IOT instruction", /* 6 SIGIOT */ |
|
489 "crash likely", /* 7 SIGDANGER */ |
|
490 "floating point exception", /* 8 SIGFPE */ |
|
491 "kill", /* 9 SIGKILL */ |
|
492 "bus error", /* 10 SIGBUS */ |
|
493 "segmentation violation", /* 11 SIGSEGV */ |
|
494 "bad argument to system call", /* 12 SIGSYS */ |
|
495 "write on a pipe with no one to read it", /* 13 SIGPIPE */ |
|
496 "alarm clock", /* 14 SIGALRM */ |
|
497 "software termination signum", /* 15 SIGTERM */ |
|
498 "user defined signal 1", /* 16 SIGUSR1 */ |
|
499 "user defined signal 2", /* 17 SIGUSR2 */ |
|
500 "death of a child", /* 18 SIGCLD */ |
|
501 "power-fail restart", /* 19 SIGPWR */ |
|
502 "bogus signal", /* 20 */ |
|
503 "bogus signal", /* 21 */ |
|
504 "bogus signal", /* 22 */ |
|
505 "bogus signal", /* 23 */ |
|
506 "bogus signal", /* 24 */ |
|
507 "LAN I/O interrupt", /* 25 SIGAIO */ |
|
508 "PTY I/O interrupt", /* 26 SIGPTY */ |
|
509 "I/O intervention required", /* 27 SIGIOINT */ |
|
510 "HFT grant", /* 28 SIGGRANT */ |
|
511 "HFT retract", /* 29 SIGRETRACT */ |
|
512 "HFT sound done", /* 30 SIGSOUND */ |
|
513 "HFT input ready", /* 31 SIGMSG */ |
|
514 #else /* not AIX */ |
2512
|
515 #ifdef __EMX__ |
|
516 "bogus signal #0", /* 0 */ |
|
517 "hangup", /* 1 SIGHUP */ |
|
518 "interrupt (Ctrl-C)", /* 2 SIGINT (Ctrl-C) */ |
|
519 "quit", /* 3 SIGQUIT */ |
|
520 "illegal instruction", /* 4 SIGILL */ |
|
521 "single step", /* 5 SIGTRAP */ |
|
522 "abort", /* 6 SIGABRT */ |
|
523 "EMT instruction", /* 7 SIGEMT */ |
|
524 "floating point exception", /* 8 SIGFPE */ |
|
525 "kill", /* 9 SIGKILL */ |
|
526 "bus error", /* 10 SIGBUS */ |
|
527 "segmentation violation", /* 11 SIGSEGV */ |
|
528 "bad argument to system call", /* 12 SIGSYS */ |
|
529 "broken pipe", /* 13 SIGPIPE */ |
|
530 "alarm clock", /* 14 SIGALRM */ |
|
531 "software termination signum", /* 15 SIGTERM */ |
|
532 "user defined signal 1", /* 16 SIGUSR1 */ |
|
533 "user defined signal 2", /* 17 SIGUSR2 */ |
|
534 "death of a child", /* 18 SIGCHLD */ |
|
535 "bogus signal #20", /* 19 */ |
|
536 "bogus signal #21", /* 20 */ |
|
537 "break (Ctrl-Break)", /* 21 SIGBREAK */ |
|
538 #else /* not __EMX__ */ |
839
|
539 "bogus signal", /* 0 */ |
|
540 "hangup", /* 1 SIGHUP */ |
|
541 "interrupt", /* 2 SIGINT */ |
|
542 "quit", /* 3 SIGQUIT */ |
|
543 "illegal instruction", /* 4 SIGILL */ |
|
544 "trace trap", /* 5 SIGTRAP */ |
|
545 "IOT instruction", /* 6 SIGIOT */ |
|
546 "EMT instruction", /* 7 SIGEMT */ |
|
547 "floating point exception", /* 8 SIGFPE */ |
|
548 "kill", /* 9 SIGKILL */ |
|
549 "bus error", /* 10 SIGBUS */ |
|
550 "segmentation violation", /* 11 SIGSEGV */ |
|
551 "bad argument to system call", /* 12 SIGSYS */ |
|
552 "write on a pipe with no one to read it", /* 13 SIGPIPE */ |
|
553 "alarm clock", /* 14 SIGALRM */ |
|
554 "software termination signum", /* 15 SIGTERM */ |
|
555 "user defined signal 1", /* 16 SIGUSR1 */ |
|
556 "user defined signal 2", /* 17 SIGUSR2 */ |
|
557 "death of a child", /* 18 SIGCLD */ |
|
558 "power-fail restart", /* 19 SIGPWR */ |
|
559 #ifdef sun |
|
560 "window size change", /* 20 SIGWINCH */ |
|
561 "urgent socket condition", /* 21 SIGURG */ |
|
562 "pollable event occured", /* 22 SIGPOLL */ |
|
563 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */ |
|
564 "user stop requested from tty", /* 24 SIGTSTP */ |
|
565 "stopped process has been continued", /* 25 SIGCONT */ |
|
566 "background tty read attempted", /* 26 SIGTTIN */ |
|
567 "background tty write attempted", /* 27 SIGTTOU */ |
|
568 "virtual timer expired", /* 28 SIGVTALRM */ |
|
569 "profiling timer expired", /* 29 SIGPROF */ |
|
570 "exceeded cpu limit", /* 30 SIGXCPU */ |
|
571 "exceeded file size limit", /* 31 SIGXFSZ */ |
|
572 "process's lwps are blocked", /* 32 SIGWAITING */ |
|
573 "special signal used by thread library", /* 33 SIGLWP */ |
|
574 #ifdef SIGFREEZE |
|
575 "Special Signal Used By CPR", /* 34 SIGFREEZE */ |
|
576 #endif |
|
577 #ifdef SIGTHAW |
|
578 "Special Signal Used By CPR", /* 35 SIGTHAW */ |
|
579 #endif |
|
580 #endif /* sun */ |
2512
|
581 #endif /* __EMX__ */ |
|
582 #endif /* AIX */ |
839
|
583 0 |
|
584 }; |
|
585 #endif |
|
586 |
2209
|
587 octave_child_list *octave_child_list::instance = 0; |
|
588 |
|
589 void |
|
590 octave_child_list::do_insert (pid_t pid, octave_child::dead_child_handler f) |
|
591 { |
|
592 // Insert item in first open slot, increasing size of list if |
|
593 // necessary. |
|
594 |
|
595 bool enlarge = true; |
|
596 |
|
597 for (int i = 0; i < curr_len; i++) |
|
598 { |
2305
|
599 octave_child& tmp = list (i); |
2209
|
600 |
|
601 if (tmp.pid < 0) |
|
602 { |
2305
|
603 list (i) = octave_child (pid, f); |
2209
|
604 enlarge = false; |
|
605 break; |
|
606 } |
|
607 } |
|
608 |
|
609 if (enlarge) |
|
610 { |
|
611 int total_len = list.length (); |
|
612 |
|
613 if (curr_len == total_len) |
|
614 { |
|
615 if (total_len == 0) |
|
616 list.resize (16); |
|
617 else |
|
618 list.resize (total_len * 2); |
|
619 } |
|
620 |
2305
|
621 list (curr_len) = octave_child (pid, f); |
2209
|
622 curr_len++; |
|
623 } |
|
624 } |
|
625 |
|
626 void |
|
627 octave_child_list::insert (pid_t pid, octave_child::dead_child_handler f) |
|
628 { |
|
629 if (! instance) |
|
630 instance = new octave_child_list (); |
|
631 |
|
632 if (instance) |
|
633 instance->do_insert (pid, f); |
|
634 else |
|
635 panic_impossible (); |
|
636 } |
|
637 |
2210
|
638 void |
|
639 octave_child_list::do_remove (pid_t pid) |
|
640 { |
|
641 // Mark the record for PID invalid. |
|
642 |
|
643 for (int i = 0; i < curr_len; i++) |
|
644 { |
2305
|
645 octave_child& tmp = list (i); |
2210
|
646 |
|
647 if (tmp.pid == pid) |
|
648 { |
|
649 tmp.pid = -1; |
|
650 break; |
|
651 } |
|
652 } |
|
653 } |
|
654 |
|
655 void |
|
656 octave_child_list::remove (pid_t pid) |
|
657 { |
|
658 if (! instance) |
|
659 instance = new octave_child_list (); |
|
660 |
|
661 if (instance) |
|
662 instance->do_remove (pid); |
|
663 else |
|
664 panic_impossible (); |
|
665 } |
|
666 |
1
|
667 /* |
|
668 ;;; Local Variables: *** |
|
669 ;;; mode: C++ *** |
|
670 ;;; End: *** |
|
671 */ |