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