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