comparison src/sighandlers.cc @ 5451:ed08548b9054

[project @ 2005-09-15 19:52:50 by jwe]
author jwe
date Thu, 15 Sep 2005 19:52:50 +0000
parents ac8d64b9e76a
children 89f5979e8552
comparison
equal deleted inserted replaced
5450:6b42c78c77d3 5451:ed08548b9054
112 { 112 {
113 octave_signals_caught[i] = false; 113 octave_signals_caught[i] = false;
114 114
115 switch (i) 115 switch (i)
116 { 116 {
117 #ifdef SIGCHLD
117 case SIGCHLD: 118 case SIGCHLD:
118 octave_child_list::reap (); 119 octave_child_list::reap ();
119 break; 120 break;
121 #endif
120 122
121 case SIGFPE: 123 case SIGFPE:
122 std::cerr << "warning: floating point exception -- trying to return to prompt" << std::endl; 124 std::cerr << "warning: floating point exception -- trying to return to prompt" << std::endl;
123 break; 125 break;
124 126
127 #ifdef SIGPIPE
125 case SIGPIPE: 128 case SIGPIPE:
126 std::cerr << "warning: broken pipe -- some output may be lost" << std::endl; 129 std::cerr << "warning: broken pipe -- some output may be lost" << std::endl;
127 break; 130 break;
131 #endif
128 } 132 }
129 } 133 }
130 } 134 }
131 } 135 }
132 136
141 #if defined (SIGABRT) 145 #if defined (SIGABRT)
142 octave_set_signal_handler (SIGABRT, SIG_DFL); 146 octave_set_signal_handler (SIGABRT, SIG_DFL);
143 #endif 147 #endif
144 148
145 std::cerr << "panic: attempted clean up apparently failed -- aborting...\n"; 149 std::cerr << "panic: attempted clean up apparently failed -- aborting...\n";
150
151 MINGW_SIGNAL_CLEANUP ();
152
146 abort (); 153 abort ();
147 } 154 }
148 else 155 else
149 { 156 {
150 been_there_done_that = true; 157 been_there_done_that = true;
153 160
154 if (save_vars) 161 if (save_vars)
155 dump_octave_core (); 162 dump_octave_core ();
156 163
157 if (sig_number < 0) 164 if (sig_number < 0)
158 exit (1); 165 {
166 MINGW_SIGNAL_CLEANUP ();
167
168 exit (1);
169 }
159 else 170 else
160 { 171 {
161 octave_set_signal_handler (sig_number, SIG_DFL); 172 octave_set_signal_handler (sig_number, SIG_DFL);
162 173
163 #if defined (HAVE_RAISE) 174 #if defined (HAVE_RAISE)
341 // 352 //
342 // This also has to work for SIGBREAK (on systems that have it), so we 353 // This also has to work for SIGBREAK (on systems that have it), so we
343 // use the value of sig, instead of just assuming that it is called 354 // use the value of sig, instead of just assuming that it is called
344 // for SIGINT only. 355 // for SIGINT only.
345 356
346 static RETSIGTYPE 357 static
347 sigint_handler (int sig) 358 void user_abort(const char *sig_name, int sig_number)
348 { 359 {
349 MAYBE_ACK_SIGNAL (sig);
350
351 MAYBE_REINSTALL_SIGHANDLER (sig, sigint_handler);
352
353 if (! octave_initialized) 360 if (! octave_initialized)
354 exit (1); 361 exit (1);
355 362
356 if (can_interrupt) 363 if (can_interrupt)
357 { 364 {
359 { 366 {
360 if (! octave_debug_on_interrupt_state) 367 if (! octave_debug_on_interrupt_state)
361 { 368 {
362 octave_debug_on_interrupt_state = true; 369 octave_debug_on_interrupt_state = true;
363 370
364 SIGHANDLER_RETURN (0); 371 return;
365 } 372 }
366 else 373 else
367 // Clear the flag and do normal interrupt stuff. 374 // Clear the flag and do normal interrupt stuff.
368 octave_debug_on_interrupt_state = false; 375 octave_debug_on_interrupt_state = false;
369 } 376 }
384 391
385 if (interactive && octave_interrupt_state == 2) 392 if (interactive && octave_interrupt_state == 2)
386 std::cerr << "Press Control-C again to abort." << std::endl; 393 std::cerr << "Press Control-C again to abort." << std::endl;
387 394
388 if (octave_interrupt_state >= 3) 395 if (octave_interrupt_state >= 3)
389 my_friendly_exit (sys_siglist[sig], sig, true); 396 my_friendly_exit (sig_name, sig_number, true);
390 } 397 }
391 } 398 }
399
400 }
401
402 static RETSIGTYPE
403 sigint_handler (int sig)
404 {
405 MAYBE_ACK_SIGNAL (sig);
406
407 MAYBE_REINSTALL_SIGHANDLER (sig, sigint_handler);
408
409 #ifdef USE_W32_SIGINT
410 if (w32_in_main_thread ())
411 user_abort (sys_siglist[sig], sig);
412 else
413 w32_raise (sig);
414 #else
415 user_abort (sys_siglist[sig], sig);
416 #endif
392 417
393 SIGHANDLER_RETURN (0); 418 SIGHANDLER_RETURN (0);
394 } 419 }
395 420
396 #ifdef SIGPIPE 421 #ifdef SIGPIPE
412 437
413 SIGHANDLER_RETURN (0); 438 SIGHANDLER_RETURN (0);
414 } 439 }
415 #endif /* defined(SIGPIPE) */ 440 #endif /* defined(SIGPIPE) */
416 441
442 #ifdef USE_W32_SIGINT
443 static BOOL CALLBACK
444 w32_sigint_handler (DWORD sig)
445 {
446 const char *sig_name;
447
448 switch(sig)
449 {
450 case CTRL_BREAK_EVENT:
451 sig_name = "Ctrl-Break";
452 break;
453 case CTRL_C_EVENT:
454 sig_name = "Ctrl-C";
455 break;
456 case CTRL_CLOSE_EVENT:
457 sig_name = "close console";
458 break;
459 case CTRL_LOGOFF_EVENT:
460 sig_name = "logoff";
461 break;
462 case CTRL_SHUTDOWN_EVENT:
463 sig_name = "shutdown";
464 break;
465 default:
466 sig_name = "unknown console event";
467 break;
468 }
469
470 switch(sig)
471 {
472 case CTRL_BREAK_EVENT:
473 case CTRL_C_EVENT:
474 w32_raise (SIGINT);
475 break;
476
477 case CTRL_CLOSE_EVENT:
478 case CTRL_LOGOFF_EVENT:
479 case CTRL_SHUTDOWN_EVENT:
480 default:
481 // We should do the following:
482 // clean_up_and_exit (0);
483 // We can't because we aren't running in the normal Octave thread.
484 user_abort(sig_name, sig);
485 break;
486 }
487
488 // Return TRUE if the event was handled, or FALSE if another handler
489 // should be called.
490 // XXX FIXME XXX check that windows terminates the thread.
491 return TRUE;
492 }
493 #endif /* w32_sigint_handler */
494
495
417 octave_interrupt_handler 496 octave_interrupt_handler
418 octave_catch_interrupts (void) 497 octave_catch_interrupts (void)
419 { 498 {
420 octave_interrupt_handler retval; 499 octave_interrupt_handler retval;
421 500
423 retval.int_handler = octave_set_signal_handler (SIGINT, sigint_handler); 502 retval.int_handler = octave_set_signal_handler (SIGINT, sigint_handler);
424 #endif 503 #endif
425 504
426 #ifdef SIGBREAK 505 #ifdef SIGBREAK
427 retval.brk_handler = octave_set_signal_handler (SIGBREAK, sigint_handler); 506 retval.brk_handler = octave_set_signal_handler (SIGBREAK, sigint_handler);
507 #endif
508
509 #ifdef USE_W32_SIGINT
510
511 // Intercept windows console control events.
512 // Note that the windows console signal handlers chain, so if
513 // install_signal_handlers is called more than once in the same program,
514 // then first call the following to avoid duplicates:
515 //
516 // SetConsoleCtrlHandler (w32_sigint_handler, FALSE);
517
518 if (! SetConsoleCtrlHandler (w32_sigint_handler, TRUE))
519 error ("SetConsoleCtrlHandler failed with %ld\n", GetLastError ());
520
521 w32_set_quiet_shutdown ();
522
428 #endif 523 #endif
429 524
430 return retval; 525 return retval;
431 } 526 }
432 527
590 #endif 685 #endif
591 686
592 #ifdef SIGXFSZ 687 #ifdef SIGXFSZ
593 octave_set_signal_handler (SIGXFSZ, generic_sig_handler); 688 octave_set_signal_handler (SIGXFSZ, generic_sig_handler);
594 #endif 689 #endif
690
595 } 691 }
596 692
597 static Octave_map 693 static Octave_map
598 make_sig_struct (void) 694 make_sig_struct (void)
599 { 695 {