26#if defined (HAVE_CONFIG_H)
37#if defined (OCTAVE_USE_WINDOWS_API)
38# define WIN32_LEAN_AND_MEAN
77static bool Vsighup_dumps_octave_core =
true;
80static bool Vsigquit_dumps_octave_core =
true;
83static bool Vsigterm_dumps_octave_core =
true;
86static std::atomic<bool> *signals_caught =
nullptr;
89my_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))
218 else if (have_sigpipe && sig == sigpipe)
220 std::cerr <<
"warning: broken pipe" << std::endl;
230 else if (have_sighup && sig == sighup)
231 my_friendly_exit (sighup, Vsighup_dumps_octave_core);
232 else if (have_sigquit && sig == sigquit)
233 my_friendly_exit (sigquit, Vsigquit_dumps_octave_core);
234 else if (have_sigterm && sig == sigterm)
235 my_friendly_exit (sigterm, Vsigterm_dumps_octave_core);
236 else if ((have_sigalrm && sig == sigalrm)
237 || (have_sigvtalrm && sig == sigvtalrm)
238 || (have_sigio && sig == sigio)
239 || (have_siglost && sig == siglost)
240 || (have_sigxcpu && sig == sigxcpu)
241 || (have_sigxfsz && sig == sigxfsz)
242 || (have_sigusr1 && sig == sigusr1)
243 || (have_sigusr2 && sig == sigusr2))
244 std::cerr <<
"warning: ignoring signal: "
247 else if ((have_sigint && sig == sigint)
248 || (have_sigbreak && sig == sigbreak))
251 std::cerr <<
"warning: ignoring unexpected signal: "
266 bool restart_syscalls)
273generic_sig_handler (
int sig)
281 signals_caught[sig] =
true;
284 static const bool have_sigint
288 static const bool have_sigbreak
291 if ((have_sigint && sig == sigint)
292 || (have_sigbreak && sig == sigbreak))
306deadly_sig_handler (
int sig)
308 std::cerr <<
"fatal: caught signal "
310 <<
" -- stopping myself..." << std::endl;
322 std::cerr <<
"warning: floating point exception" << std::endl;
366 if (! signals_caught)
370 signals_caught[i] =
false;
451 set_sig_struct_field (m,
"SIGABRT");
452 set_sig_struct_field (m,
"SIGALRM");
453 set_sig_struct_field (m,
"SIGBUS");
454 set_sig_struct_field (m,
"SIGCHLD");
455 set_sig_struct_field (m,
"SIGCLD");
456 set_sig_struct_field (m,
"SIGCONT");
457 set_sig_struct_field (m,
"SIGEMT");
458 set_sig_struct_field (m,
"SIGFPE");
459 set_sig_struct_field (m,
"SIGHUP");
460 set_sig_struct_field (m,
"SIGILL");
461 set_sig_struct_field (m,
"SIGINFO");
462 set_sig_struct_field (m,
"SIGINT");
463 set_sig_struct_field (m,
"SIGIO");
464 set_sig_struct_field (m,
"SIGIOT");
465 set_sig_struct_field (m,
"SIGKILL");
466 set_sig_struct_field (m,
"SIGLOST");
467 set_sig_struct_field (m,
"SIGPIPE");
468 set_sig_struct_field (m,
"SIGPOLL");
469 set_sig_struct_field (m,
"SIGPROF");
470 set_sig_struct_field (m,
"SIGPWR");
471 set_sig_struct_field (m,
"SIGQUIT");
472 set_sig_struct_field (m,
"SIGSEGV");
473 set_sig_struct_field (m,
"SIGSTKFLT");
474 set_sig_struct_field (m,
"SIGSTOP");
475 set_sig_struct_field (m,
"SIGSYS");
476 set_sig_struct_field (m,
"SIGTERM");
477 set_sig_struct_field (m,
"SIGTRAP");
478 set_sig_struct_field (m,
"SIGTSTP");
479 set_sig_struct_field (m,
"SIGTTIN");
480 set_sig_struct_field (m,
"SIGTTOU");
481 set_sig_struct_field (m,
"SIGUNUSED");
482 set_sig_struct_field (m,
"SIGURG");
483 set_sig_struct_field (m,
"SIGUSR1");
484 set_sig_struct_field (m,
"SIGUSR2");
485 set_sig_struct_field (m,
"SIGVTALRM");
486 set_sig_struct_field (m,
"SIGWINCH");
487 set_sig_struct_field (m,
"SIGXCPU");
488 set_sig_struct_field (m,
"SIGXFSZ");
499 if (args.length () != 0)
514DEFUN (debug_on_interrupt, args, nargout,
533 "debug_on_interrupt");
548DEFUN (sighup_dumps_octave_core, args, nargout,
564 "sighup_dumps_octave_core");
579DEFUN (sigquit_dumps_octave_core, args, nargout,
595 "sigquit_dumps_octave_core");
610DEFUN (sigterm_dumps_octave_core, args, nargout,
626 "sigterm_dumps_octave_core");
641OCTAVE_END_NAMESPACE(octave)
void assign(const std::string &k, const octave_value &val)
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.
child_list & __get_child_list__()
load_save_system & __get_load_save_system__()
std::atomic< bool > octave_initialized
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
std::atomic< bool > octave_signal_caught
std::atomic< sig_atomic_t > octave_interrupt_state
interrupt_handler ignore_interrupts()
void respond_to_pending_signals()
int pipe_handler_error_count
sig_handler * set_signal_handler(int sig, sig_handler *handler, bool restart_syscalls)
interrupt_handler set_interrupt_handler(const interrupt_handler &h, bool restart_syscalls)
std::atomic< bool > can_interrupt
interrupt_handler catch_interrupts()
void install_signal_handlers()
void * octave_block_child(void)
int octave_num_signals(void)
void octave_unblock_child(void *context_arg)
bool octave_get_sig_number(const char *signame, int *signum)
char * octave_strsignal_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)
octave_sig_handler * octave_set_default_signal_handler(int sig)
int octave_raise_wrapper(int signum)
sig_handler * int_handler
sig_handler * brk_handler
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)