comparison src/sighandlers.cc @ 4787:02c748eb2ddc

[project @ 2004-02-18 21:20:26 by jwe]
author jwe
date Wed, 18 Feb 2004 21:20:26 +0000
parents f6d6335c08f6
children 62f2fb593455
comparison
equal deleted inserted replaced
4786:fc316bde0053 4787:02c748eb2ddc
44 #include "load-save.h" 44 #include "load-save.h"
45 #include "oct-map.h" 45 #include "oct-map.h"
46 #include "pager.h" 46 #include "pager.h"
47 #include "pt-bp.h" 47 #include "pt-bp.h"
48 #include "sighandlers.h" 48 #include "sighandlers.h"
49 #include "sysdep.h"
49 #include "syswait.h" 50 #include "syswait.h"
50 #include "toplev.h" 51 #include "toplev.h"
51 #include "utils.h" 52 #include "utils.h"
52 53
53 // Nonzero means we have already printed a message for this series of 54 // Nonzero means we have already printed a message for this series of
91 #define MAYBE_ACK_SIGNAL(sig) \ 92 #define MAYBE_ACK_SIGNAL(sig) \
92 do { } while (0) 93 do { } while (0)
93 #endif 94 #endif
94 95
95 static void 96 static void
96 my_friendly_exit (const char *sig_name, int sig_number) 97 my_friendly_exit (const char *sig_name, int sig_number,
98 bool save_vars = true)
97 { 99 {
98 static bool been_there_done_that = false; 100 static bool been_there_done_that = false;
99 101
100 if (been_there_done_that) 102 if (been_there_done_that)
101 { 103 {
110 { 112 {
111 been_there_done_that = true; 113 been_there_done_that = true;
112 114
113 std::cerr << "panic: " << sig_name << " -- stopping myself...\n"; 115 std::cerr << "panic: " << sig_name << " -- stopping myself...\n";
114 116
115 save_user_variables (); 117 if (save_vars)
118 save_user_variables ();
116 119
117 if (sig_number < 0) 120 if (sig_number < 0)
118 exit (1); 121 exit (1);
119 else 122 else
120 { 123 {
233 236
234 // XXX FIXME XXX -- will setting octave_interrupt_state really help 237 // XXX FIXME XXX -- will setting octave_interrupt_state really help
235 // here? 238 // here?
236 239
237 if (can_interrupt) 240 if (can_interrupt)
238 octave_interrupt_state = 1; 241 octave_interrupt_state++;
239 242
240 SIGHANDLER_RETURN (0); 243 SIGHANDLER_RETURN (0);
241 } 244 }
242 #endif /* defined(__alpha__) */ 245 #endif /* defined(__alpha__) */
243 #endif /* defined(SIGFPE) */ 246 #endif /* defined(SIGFPE) */
301 // This also has to work for SIGBREAK (on systems that have it), so we 304 // This also has to work for SIGBREAK (on systems that have it), so we
302 // use the value of sig, instead of just assuming that it is called 305 // use the value of sig, instead of just assuming that it is called
303 // for SIGINT only. 306 // for SIGINT only.
304 307
305 static RETSIGTYPE 308 static RETSIGTYPE
306 #if defined (ACK_USES_SIG) || defined (REINSTALL_USES_SIG)
307 sigint_handler (int sig) 309 sigint_handler (int sig)
308 #else
309 sigint_handler (int)
310 #endif
311 { 310 {
312 MAYBE_ACK_SIGNAL (sig); 311 MAYBE_ACK_SIGNAL (sig);
313 312
314 MAYBE_REINSTALL_SIGHANDLER (sig, sigint_handler); 313 MAYBE_REINSTALL_SIGHANDLER (sig, sigint_handler);
315 314
332 } 331 }
333 332
334 if (octave_interrupt_immediately) 333 if (octave_interrupt_immediately)
335 octave_jump_to_enclosing_context (); 334 octave_jump_to_enclosing_context ();
336 else 335 else
337 octave_interrupt_state = 1; 336 {
337 octave_interrupt_state++;
338
339 if (interactive)
340 {
341 if (octave_interrupt_state > 3)
342 {
343 // XXX FIXME XXX -- might want to attempt to flush
344 // any pending input first...
345
346 std::cerr << "abort [y/N]? ";
347
348 int c = octave_kbhit ();
349
350 std::cerr << static_cast<char> (c) << std::endl;
351
352 if (c == 'y' || c == 'Y')
353 {
354 std::cerr << "save top-level workspace [y/N]? ";
355
356 c = octave_kbhit ();
357
358 std::cerr << static_cast<char> (c) << std::endl;
359
360 my_friendly_exit (sys_siglist[sig], sig,
361 (c == 'y' || c == 'Y'));
362 }
363 else
364 {
365 // We will still eventually interrupt and jump to
366 // the top level even if no additional interrupts
367 // happen, but we will have to wait until it is
368 // safe to do so. It will take 3 more
369 // consecutive interrupts before we offer to
370 // abort again.
371
372 octave_interrupt_state = 1;
373 }
374 }
375 }
376 }
338 } 377 }
339 378
340 SIGHANDLER_RETURN (0); 379 SIGHANDLER_RETURN (0);
341 } 380 }
342 381
355 394
356 // XXX FIXME XXX -- will setting octave_interrupt_state really help 395 // XXX FIXME XXX -- will setting octave_interrupt_state really help
357 // here? 396 // here?
358 397
359 if (pipe_handler_error_count > 100) 398 if (pipe_handler_error_count > 100)
360 octave_interrupt_state = 1; 399 octave_interrupt_state++;
361 400
362 SIGHANDLER_RETURN (0); 401 SIGHANDLER_RETURN (0);
363 } 402 }
364 #endif /* defined(SIGPIPE) */ 403 #endif /* defined(SIGPIPE) */
365 404