26 #if defined (HAVE_CONFIG_H)
37 #if defined (OCTAVE_USE_WINDOWS_API)
38 # define WIN32_LEAN_AND_MEAN
77 static bool Vsighup_dumps_octave_core =
true;
80 static bool Vsigquit_dumps_octave_core =
true;
83 static bool Vsigterm_dumps_octave_core =
true;
86 static std::atomic<bool> *signals_caught =
nullptr;
89 my_friendly_exit (
int sig,
bool save_vars =
true)
91 std::cerr <<
"fatal: caught signal "
93 <<
" -- stopping myself..." << std::endl;
104 throw exit_exception (1);
119 static const bool have_sigint
123 static const bool have_sigbreak
129 static const bool have_sighup
133 static const bool have_sigquit
137 static const bool have_sigterm
143 static const bool have_sigalrm
146 static int sigvtalrm;
147 static const bool have_sigvtalrm
153 static const bool have_sigio
157 static const bool have_siglost
161 static const bool have_sigpipe
167 static const bool have_sigchld
171 static const bool have_sigcld
177 static const bool have_sigxcpu
181 static const bool have_sigxfsz
187 static const bool have_sigusr1
191 static const bool have_sigusr2
198 bool expected =
true;
200 if (signals_caught[sig].compare_exchange_strong (expected,
false))
202 if ((have_sigchld && sig == sigchld)
203 || (have_sigcld && sig == sigcld))
219 else if (have_sigpipe && sig == sigpipe)
221 std::cerr <<
"warning: broken pipe" << std::endl;
231 else if (have_sighup && sig == sighup)
232 my_friendly_exit (sighup, Vsighup_dumps_octave_core);
233 else if (have_sigquit && sig == sigquit)
234 my_friendly_exit (sigquit, Vsigquit_dumps_octave_core);
235 else if (have_sigterm && sig == sigterm)
236 my_friendly_exit (sigterm, Vsigterm_dumps_octave_core);
237 else if ((have_sigalrm && sig == sigalrm)
238 || (have_sigvtalrm && sig == sigvtalrm)
239 || (have_sigio && sig == sigio)
240 || (have_siglost && sig == siglost)
241 || (have_sigxcpu && sig == sigxcpu)
242 || (have_sigxfsz && sig == sigxfsz)
243 || (have_sigusr1 && sig == sigusr1)
244 || (have_sigusr2 && sig == sigusr2))
245 std::cerr <<
"warning: ignoring signal: "
248 else if ((have_sigint && sig == sigint)
249 || (have_sigbreak && sig == sigbreak))
252 std::cerr <<
"warning: ignoring unexpected signal: "
267 bool restart_syscalls)
274 generic_sig_handler (
int sig)
282 signals_caught[sig] =
true;
285 static const bool have_sigint
289 static const bool have_sigbreak
292 if ((have_sigint && sig == sigint)
293 || (have_sigbreak && sig == sigbreak))
307 deadly_sig_handler (
int sig)
309 std::cerr <<
"fatal: caught signal "
311 <<
" -- stopping myself..." << std::endl;
319 fpe_sig_handler (
int)
323 std::cerr <<
"warning: floating point exception" << std::endl;
350 bool restart_syscalls)
368 if (! signals_caught)
372 signals_caught[i] =
false;
445 m.assign (&signame[3],
signum);
453 set_sig_struct_field (
m,
"SIGABRT");
454 set_sig_struct_field (
m,
"SIGALRM");
455 set_sig_struct_field (
m,
"SIGBUS");
456 set_sig_struct_field (
m,
"SIGCHLD");
457 set_sig_struct_field (
m,
"SIGCLD");
458 set_sig_struct_field (
m,
"SIGCONT");
459 set_sig_struct_field (
m,
"SIGEMT");
460 set_sig_struct_field (
m,
"SIGFPE");
461 set_sig_struct_field (
m,
"SIGHUP");
462 set_sig_struct_field (
m,
"SIGILL");
463 set_sig_struct_field (
m,
"SIGINFO");
464 set_sig_struct_field (
m,
"SIGINT");
465 set_sig_struct_field (
m,
"SIGIO");
466 set_sig_struct_field (
m,
"SIGIOT");
467 set_sig_struct_field (
m,
"SIGKILL");
468 set_sig_struct_field (
m,
"SIGLOST");
469 set_sig_struct_field (
m,
"SIGPIPE");
470 set_sig_struct_field (
m,
"SIGPOLL");
471 set_sig_struct_field (
m,
"SIGPROF");
472 set_sig_struct_field (
m,
"SIGPWR");
473 set_sig_struct_field (
m,
"SIGQUIT");
474 set_sig_struct_field (
m,
"SIGSEGV");
475 set_sig_struct_field (
m,
"SIGSTKFLT");
476 set_sig_struct_field (
m,
"SIGSTOP");
477 set_sig_struct_field (
m,
"SIGSYS");
478 set_sig_struct_field (
m,
"SIGTERM");
479 set_sig_struct_field (
m,
"SIGTRAP");
480 set_sig_struct_field (
m,
"SIGTSTP");
481 set_sig_struct_field (
m,
"SIGTTIN");
482 set_sig_struct_field (
m,
"SIGTTOU");
483 set_sig_struct_field (
m,
"SIGUNUSED");
484 set_sig_struct_field (
m,
"SIGURG");
485 set_sig_struct_field (
m,
"SIGUSR1");
486 set_sig_struct_field (
m,
"SIGUSR2");
487 set_sig_struct_field (
m,
"SIGVTALRM");
488 set_sig_struct_field (
m,
"SIGWINCH");
489 set_sig_struct_field (
m,
"SIGXCPU");
490 set_sig_struct_field (
m,
"SIGXFSZ");
501 if (args.length () != 0)
516 DEFUN (debug_on_interrupt, args, nargout,
535 "debug_on_interrupt");
550 DEFUN (sighup_dumps_octave_core, args, nargout,
566 "sighup_dumps_octave_core");
581 DEFUN (sigquit_dumps_octave_core, args, nargout,
597 "sigquit_dumps_octave_core");
612 DEFUN (sigterm_dumps_octave_core, args, nargout,
628 "sigterm_dumps_octave_core");
643 OCTAVE_END_NAMESPACE(
octave)
void octave_create_interrupt_watcher_thread(octave_sig_handler *handler)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
load_save_system & __get_load_save_system__()
child_list & __get_child_list__()
std::atomic< bool > octave_initialized
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
std::atomic< sig_atomic_t > octave_interrupt_state
volatile std::atomic< bool > octave_signal_caught
interrupt_handler ignore_interrupts()
interrupt_handler set_interrupt_handler(const volatile interrupt_handler &h, bool restart_syscalls)
void respond_to_pending_signals()
int pipe_handler_error_count
sig_handler * set_signal_handler(int sig, sig_handler *handler, bool restart_syscalls)
std::atomic< bool > can_interrupt
interrupt_handler catch_interrupts()
void install_signal_handlers()
octave_sig_handler * octave_set_default_signal_handler(int sig)
int octave_num_signals(void)
void * octave_block_child(void)
char * octave_strsignal_wrapper(int signum)
void octave_unblock_child(void *context_arg)
bool octave_get_sig_number(const char *signame, int *signum)
int octave_raise_wrapper(int signum)
octave_sig_handler * octave_set_signal_handler_by_name(const char *signame, octave_sig_handler *handler, bool restart_syscalls)
octave_sig_handler * octave_set_signal_handler_internal(int sig, octave_sig_handler *handler, bool restart_syscalls)
sig_handler * int_handler
sig_handler * brk_handler