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__) |
|
83 #define MAYBE_UNBLOCK_SIGNAL(sig) \ |
|
84 octave_set_signal_handler (sig, SIG_ACK) |
|
85 #else |
|
86 #define MAYBE_UNBLOCK_SIGNAL(sig) \ |
|
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 #if defined (__EMX__) |
|
193 volatile octave_interrupt_handler *saved_interrupt_handler |
|
194 = octave_ignore_interrupts (); |
|
195 |
|
196 volatile sig_handler *saved_sigchld_handler |
2600
|
197 = octave_set_signal_hanlder (SIGCHLD, SIG_IGN); |
2554
|
198 #endif |
|
199 |
2209
|
200 int n = octave_child_list::length (); |
|
201 |
2554
|
202 if (n == 0) |
1230
|
203 { |
2554
|
204 waitpid (-1, 0, WNOHANG); |
|
205 } |
|
206 else |
|
207 { |
|
208 for (int i = 0; i < n; i++) |
|
209 { |
|
210 octave_child& elt = octave_child_list::elem (i); |
2209
|
211 |
2554
|
212 pid_t pid = elt.pid; |
2209
|
213 |
2554
|
214 if (pid > 0) |
2091
|
215 { |
2554
|
216 int status; |
|
217 |
|
218 if (waitpid (pid, &status, WNOHANG) > 0) |
|
219 { |
|
220 elt.pid = -1; |
2197
|
221 |
2554
|
222 octave_child::dead_child_handler f = elt.handler; |
2197
|
223 |
2554
|
224 if (f) |
|
225 f (pid, status); |
2209
|
226 |
2554
|
227 break; |
|
228 } |
2091
|
229 } |
1230
|
230 } |
|
231 } |
2469
|
232 |
2554
|
233 #if defined (__EMX__) |
2600
|
234 octave_set_interrupt_handler (saved_interrupt_handler); |
2554
|
235 |
|
236 octave_set_signal_handler (SIGCHLD, saved_sigchld_handler); |
2475
|
237 #endif |
|
238 |
2554
|
239 MAYBE_UNBLOCK_SIGNAL (SIGCHLD); |
|
240 |
|
241 MAYBE_REINSTALL_SIGHANDLER (SIGCHLD, sigchld_handler); |
|
242 |
2469
|
243 SIGHANDLER_RETURN (0); |
1230
|
244 } |
|
245 |
1373
|
246 #if defined (__alpha__) |
|
247 static RETSIGTYPE |
1488
|
248 sigfpe_handler (int /* sig */) |
1373
|
249 { |
2554
|
250 MAYBE_UNBLOCK_SIGNAL (SIGFPE); |
|
251 |
|
252 MAYBE_REINSTALL_SIGHANDLER (SIGFPE, sigfpe_handler); |
1373
|
253 |
1394
|
254 error ("floating point exception -- trying to return to prompt"); |
1373
|
255 |
|
256 if (can_interrupt) |
|
257 { |
|
258 jump_to_top_level (); |
|
259 panic_impossible (); |
|
260 } |
|
261 |
2469
|
262 SIGHANDLER_RETURN (0); |
1373
|
263 } |
|
264 #endif |
|
265 |
635
|
266 // Handle SIGINT by restarting the parser (see octave.cc). |
2554
|
267 // |
|
268 // This also has to work for SIGBREAK (on systems that have it), so we |
|
269 // use the value of sig, instead of just assuming that it is called |
|
270 // for SIGINT only. |
635
|
271 |
1
|
272 static RETSIGTYPE |
2554
|
273 sigint_handler (int sig) |
1
|
274 { |
2554
|
275 MAYBE_UNBLOCK_SIGNAL (sig); |
|
276 |
|
277 MAYBE_REINSTALL_SIGHANDLER (sig, sigint_handler); |
834
|
278 |
1
|
279 if (can_interrupt) |
|
280 { |
|
281 jump_to_top_level (); |
|
282 panic_impossible (); |
|
283 } |
|
284 |
2469
|
285 SIGHANDLER_RETURN (0); |
1
|
286 } |
|
287 |
|
288 static RETSIGTYPE |
1488
|
289 sigpipe_handler (int /* sig */) |
1
|
290 { |
2554
|
291 MAYBE_UNBLOCK_SIGNAL (SIGPIPE); |
|
292 |
|
293 MAYBE_REINSTALL_SIGHANDLER (SIGPIPE, sigpipe_handler); |
834
|
294 |
1
|
295 if (pipe_handler_error_count++ == 0) |
2206
|
296 warning ("broken pipe"); |
1
|
297 |
1358
|
298 // Don't loop forever on account of this. |
|
299 |
1
|
300 if (pipe_handler_error_count > 100) |
|
301 jump_to_top_level (); |
|
302 |
2469
|
303 SIGHANDLER_RETURN (0); |
1
|
304 } |
|
305 |
1651
|
306 void |
2554
|
307 octave_catch_interrupts (void) |
|
308 { |
|
309 #ifdef SIGINT |
|
310 octave_set_signal_handler (SIGINT, sigint_handler); |
|
311 |
|
312 the_interrupt_handler.int_handler = sigint_handler; |
|
313 #endif |
|
314 |
|
315 #ifdef SIGBREAK |
|
316 octave_set_signal_handler (SIGBREAK, sigint_handler); |
|
317 |
|
318 the_interrupt_handler.brk_handler = sigint_handler; |
|
319 #endif |
|
320 } |
|
321 |
|
322 octave_interrupt_handler * |
|
323 octave_ignore_interrupts (void) |
1651
|
324 { |
2554
|
325 #ifdef SIGINT |
|
326 the_interrupt_handler.int_handler |
|
327 = octave_set_signal_handler (SIGINT, SIG_IGN); |
|
328 #endif |
|
329 |
|
330 #ifdef SIGBREAK |
|
331 the_interrupt_handler.int_handler |
|
332 = octave_set_signal_handler (SIGBREAK, SIG_IGN); |
|
333 #endif |
|
334 |
|
335 return &the_interrupt_handler; |
|
336 } |
|
337 |
|
338 octave_interrupt_handler * |
|
339 octave_set_interrupt_handler (const volatile octave_interrupt_handler *h) |
|
340 { |
|
341 if (h) |
|
342 { |
|
343 #ifdef SIGINT |
|
344 the_interrupt_handler.int_handler |
|
345 = octave_set_signal_handler (SIGINT, h->int_handler); |
|
346 #endif |
|
347 |
|
348 #ifdef SIGBREAK |
|
349 the_interrupt_handler.int_handler |
|
350 = octave_set_signal_handler (SIGBREAK, h->brk_handler); |
|
351 #endif |
|
352 } |
|
353 |
|
354 return &the_interrupt_handler; |
1651
|
355 } |
|
356 |
635
|
357 // Install all the handlers for the signals we might care about. |
|
358 |
1
|
359 void |
|
360 install_signal_handlers (void) |
|
361 { |
635
|
362 set_new_handler (octave_new_handler); |
|
363 |
2554
|
364 octave_catch_interrupts (); |
|
365 |
1
|
366 #ifdef SIGABRT |
1446
|
367 octave_set_signal_handler (SIGABRT, generic_sig_handler); |
1
|
368 #endif |
|
369 |
|
370 #ifdef SIGALRM |
1446
|
371 octave_set_signal_handler (SIGALRM, generic_sig_handler); |
1
|
372 #endif |
|
373 |
|
374 #ifdef SIGBUS |
1446
|
375 octave_set_signal_handler (SIGBUS, generic_sig_handler); |
1
|
376 #endif |
|
377 |
1230
|
378 #ifdef SIGCHLD |
1446
|
379 octave_set_signal_handler (SIGCHLD, sigchld_handler); |
1230
|
380 #endif |
|
381 |
1
|
382 #ifdef SIGEMT |
1446
|
383 octave_set_signal_handler (SIGEMT, generic_sig_handler); |
1
|
384 #endif |
|
385 |
|
386 #ifdef SIGFPE |
1373
|
387 #if defined (__alpha__) |
1446
|
388 octave_set_signal_handler (SIGFPE, sigfpe_handler); |
1373
|
389 #else |
1446
|
390 octave_set_signal_handler (SIGFPE, generic_sig_handler); |
1
|
391 #endif |
1373
|
392 #endif |
1
|
393 |
|
394 #ifdef SIGHUP |
1446
|
395 octave_set_signal_handler (SIGHUP, generic_sig_handler); |
1
|
396 #endif |
|
397 |
|
398 #ifdef SIGILL |
1446
|
399 octave_set_signal_handler (SIGILL, generic_sig_handler); |
1
|
400 #endif |
|
401 |
|
402 #ifdef SIGIOT |
1446
|
403 octave_set_signal_handler (SIGIOT, generic_sig_handler); |
1
|
404 #endif |
|
405 |
|
406 #ifdef SIGLOST |
1446
|
407 octave_set_signal_handler (SIGLOST, generic_sig_handler); |
1
|
408 #endif |
|
409 |
|
410 #ifdef SIGPIPE |
1446
|
411 octave_set_signal_handler (SIGPIPE, sigpipe_handler); |
1
|
412 #endif |
|
413 |
|
414 #ifdef SIGPOLL |
1446
|
415 octave_set_signal_handler (SIGPOLL, SIG_IGN); |
1
|
416 #endif |
|
417 |
|
418 #ifdef SIGPROF |
1446
|
419 octave_set_signal_handler (SIGPROF, generic_sig_handler); |
1
|
420 #endif |
|
421 |
|
422 #ifdef SIGQUIT |
1446
|
423 octave_set_signal_handler (SIGQUIT, generic_sig_handler); |
1
|
424 #endif |
|
425 |
|
426 #ifdef SIGSEGV |
1446
|
427 octave_set_signal_handler (SIGSEGV, generic_sig_handler); |
1
|
428 #endif |
|
429 |
|
430 #ifdef SIGSYS |
1446
|
431 octave_set_signal_handler (SIGSYS, generic_sig_handler); |
1
|
432 #endif |
|
433 |
|
434 #ifdef SIGTERM |
1446
|
435 octave_set_signal_handler (SIGTERM, generic_sig_handler); |
1
|
436 #endif |
|
437 |
|
438 #ifdef SIGTRAP |
1446
|
439 octave_set_signal_handler (SIGTRAP, generic_sig_handler); |
1
|
440 #endif |
|
441 |
|
442 #ifdef SIGUSR1 |
1446
|
443 octave_set_signal_handler (SIGUSR1, generic_sig_handler); |
1
|
444 #endif |
|
445 |
|
446 #ifdef SIGUSR2 |
1446
|
447 octave_set_signal_handler (SIGUSR2, generic_sig_handler); |
1
|
448 #endif |
|
449 |
|
450 #ifdef SIGVTALRM |
1446
|
451 octave_set_signal_handler (SIGVTALRM, generic_sig_handler); |
1
|
452 #endif |
|
453 |
895
|
454 #ifdef SIGIO |
1446
|
455 octave_set_signal_handler (SIGIO, SIG_IGN); |
895
|
456 #endif |
|
457 |
1
|
458 #ifdef SIGXCPU |
1446
|
459 octave_set_signal_handler (SIGXCPU, generic_sig_handler); |
1
|
460 #endif |
|
461 |
|
462 #ifdef SIGXFSZ |
1446
|
463 octave_set_signal_handler (SIGXFSZ, generic_sig_handler); |
1
|
464 #endif |
|
465 } |
|
466 |
886
|
467 #ifndef HAVE_SYS_SIGLIST |
839
|
468 char *sys_siglist[NSIG + 1] = |
|
469 { |
|
470 #ifdef AIX |
|
471 /* AIX has changed the signals a bit */ |
|
472 "bogus signal", /* 0 */ |
|
473 "hangup", /* 1 SIGHUP */ |
|
474 "interrupt", /* 2 SIGINT */ |
|
475 "quit", /* 3 SIGQUIT */ |
|
476 "illegal instruction", /* 4 SIGILL */ |
|
477 "trace trap", /* 5 SIGTRAP */ |
|
478 "IOT instruction", /* 6 SIGIOT */ |
|
479 "crash likely", /* 7 SIGDANGER */ |
|
480 "floating point exception", /* 8 SIGFPE */ |
|
481 "kill", /* 9 SIGKILL */ |
|
482 "bus error", /* 10 SIGBUS */ |
|
483 "segmentation violation", /* 11 SIGSEGV */ |
|
484 "bad argument to system call", /* 12 SIGSYS */ |
|
485 "write on a pipe with no one to read it", /* 13 SIGPIPE */ |
|
486 "alarm clock", /* 14 SIGALRM */ |
|
487 "software termination signum", /* 15 SIGTERM */ |
|
488 "user defined signal 1", /* 16 SIGUSR1 */ |
|
489 "user defined signal 2", /* 17 SIGUSR2 */ |
|
490 "death of a child", /* 18 SIGCLD */ |
|
491 "power-fail restart", /* 19 SIGPWR */ |
|
492 "bogus signal", /* 20 */ |
|
493 "bogus signal", /* 21 */ |
|
494 "bogus signal", /* 22 */ |
|
495 "bogus signal", /* 23 */ |
|
496 "bogus signal", /* 24 */ |
|
497 "LAN I/O interrupt", /* 25 SIGAIO */ |
|
498 "PTY I/O interrupt", /* 26 SIGPTY */ |
|
499 "I/O intervention required", /* 27 SIGIOINT */ |
|
500 "HFT grant", /* 28 SIGGRANT */ |
|
501 "HFT retract", /* 29 SIGRETRACT */ |
|
502 "HFT sound done", /* 30 SIGSOUND */ |
|
503 "HFT input ready", /* 31 SIGMSG */ |
|
504 #else /* not AIX */ |
2512
|
505 #ifdef __EMX__ |
|
506 "bogus signal #0", /* 0 */ |
|
507 "hangup", /* 1 SIGHUP */ |
|
508 "interrupt (Ctrl-C)", /* 2 SIGINT (Ctrl-C) */ |
|
509 "quit", /* 3 SIGQUIT */ |
|
510 "illegal instruction", /* 4 SIGILL */ |
|
511 "single step", /* 5 SIGTRAP */ |
|
512 "abort", /* 6 SIGABRT */ |
|
513 "EMT instruction", /* 7 SIGEMT */ |
|
514 "floating point exception", /* 8 SIGFPE */ |
|
515 "kill", /* 9 SIGKILL */ |
|
516 "bus error", /* 10 SIGBUS */ |
|
517 "segmentation violation", /* 11 SIGSEGV */ |
|
518 "bad argument to system call", /* 12 SIGSYS */ |
|
519 "broken pipe", /* 13 SIGPIPE */ |
|
520 "alarm clock", /* 14 SIGALRM */ |
|
521 "software termination signum", /* 15 SIGTERM */ |
|
522 "user defined signal 1", /* 16 SIGUSR1 */ |
|
523 "user defined signal 2", /* 17 SIGUSR2 */ |
|
524 "death of a child", /* 18 SIGCHLD */ |
|
525 "bogus signal #20", /* 19 */ |
|
526 "bogus signal #21", /* 20 */ |
|
527 "break (Ctrl-Break)", /* 21 SIGBREAK */ |
|
528 #else /* not __EMX__ */ |
839
|
529 "bogus signal", /* 0 */ |
|
530 "hangup", /* 1 SIGHUP */ |
|
531 "interrupt", /* 2 SIGINT */ |
|
532 "quit", /* 3 SIGQUIT */ |
|
533 "illegal instruction", /* 4 SIGILL */ |
|
534 "trace trap", /* 5 SIGTRAP */ |
|
535 "IOT instruction", /* 6 SIGIOT */ |
|
536 "EMT instruction", /* 7 SIGEMT */ |
|
537 "floating point exception", /* 8 SIGFPE */ |
|
538 "kill", /* 9 SIGKILL */ |
|
539 "bus error", /* 10 SIGBUS */ |
|
540 "segmentation violation", /* 11 SIGSEGV */ |
|
541 "bad argument to system call", /* 12 SIGSYS */ |
|
542 "write on a pipe with no one to read it", /* 13 SIGPIPE */ |
|
543 "alarm clock", /* 14 SIGALRM */ |
|
544 "software termination signum", /* 15 SIGTERM */ |
|
545 "user defined signal 1", /* 16 SIGUSR1 */ |
|
546 "user defined signal 2", /* 17 SIGUSR2 */ |
|
547 "death of a child", /* 18 SIGCLD */ |
|
548 "power-fail restart", /* 19 SIGPWR */ |
|
549 #ifdef sun |
|
550 "window size change", /* 20 SIGWINCH */ |
|
551 "urgent socket condition", /* 21 SIGURG */ |
|
552 "pollable event occured", /* 22 SIGPOLL */ |
|
553 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */ |
|
554 "user stop requested from tty", /* 24 SIGTSTP */ |
|
555 "stopped process has been continued", /* 25 SIGCONT */ |
|
556 "background tty read attempted", /* 26 SIGTTIN */ |
|
557 "background tty write attempted", /* 27 SIGTTOU */ |
|
558 "virtual timer expired", /* 28 SIGVTALRM */ |
|
559 "profiling timer expired", /* 29 SIGPROF */ |
|
560 "exceeded cpu limit", /* 30 SIGXCPU */ |
|
561 "exceeded file size limit", /* 31 SIGXFSZ */ |
|
562 "process's lwps are blocked", /* 32 SIGWAITING */ |
|
563 "special signal used by thread library", /* 33 SIGLWP */ |
|
564 #ifdef SIGFREEZE |
|
565 "Special Signal Used By CPR", /* 34 SIGFREEZE */ |
|
566 #endif |
|
567 #ifdef SIGTHAW |
|
568 "Special Signal Used By CPR", /* 35 SIGTHAW */ |
|
569 #endif |
|
570 #endif /* sun */ |
2512
|
571 #endif /* __EMX__ */ |
|
572 #endif /* AIX */ |
839
|
573 0 |
|
574 }; |
|
575 #endif |
|
576 |
2209
|
577 octave_child_list *octave_child_list::instance = 0; |
|
578 |
|
579 void |
|
580 octave_child_list::do_insert (pid_t pid, octave_child::dead_child_handler f) |
|
581 { |
|
582 // Insert item in first open slot, increasing size of list if |
|
583 // necessary. |
|
584 |
|
585 bool enlarge = true; |
|
586 |
|
587 for (int i = 0; i < curr_len; i++) |
|
588 { |
2305
|
589 octave_child& tmp = list (i); |
2209
|
590 |
|
591 if (tmp.pid < 0) |
|
592 { |
2305
|
593 list (i) = octave_child (pid, f); |
2209
|
594 enlarge = false; |
|
595 break; |
|
596 } |
|
597 } |
|
598 |
|
599 if (enlarge) |
|
600 { |
|
601 int total_len = list.length (); |
|
602 |
|
603 if (curr_len == total_len) |
|
604 { |
|
605 if (total_len == 0) |
|
606 list.resize (16); |
|
607 else |
|
608 list.resize (total_len * 2); |
|
609 } |
|
610 |
2305
|
611 list (curr_len) = octave_child (pid, f); |
2209
|
612 curr_len++; |
|
613 } |
|
614 } |
|
615 |
|
616 void |
|
617 octave_child_list::insert (pid_t pid, octave_child::dead_child_handler f) |
|
618 { |
|
619 if (! instance) |
|
620 instance = new octave_child_list (); |
|
621 |
|
622 if (instance) |
|
623 instance->do_insert (pid, f); |
|
624 else |
|
625 panic_impossible (); |
|
626 } |
|
627 |
2210
|
628 void |
|
629 octave_child_list::do_remove (pid_t pid) |
|
630 { |
|
631 // Mark the record for PID invalid. |
|
632 |
|
633 for (int i = 0; i < curr_len; i++) |
|
634 { |
2305
|
635 octave_child& tmp = list (i); |
2210
|
636 |
|
637 if (tmp.pid == pid) |
|
638 { |
|
639 tmp.pid = -1; |
|
640 break; |
|
641 } |
|
642 } |
|
643 } |
|
644 |
|
645 void |
|
646 octave_child_list::remove (pid_t pid) |
|
647 { |
|
648 if (! instance) |
|
649 instance = new octave_child_list (); |
|
650 |
|
651 if (instance) |
|
652 instance->do_remove (pid); |
|
653 else |
|
654 panic_impossible (); |
|
655 } |
|
656 |
1
|
657 /* |
|
658 ;;; Local Variables: *** |
|
659 ;;; mode: C++ *** |
|
660 ;;; End: *** |
|
661 */ |