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