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