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