31 #if defined (HAVE_CONFIG_H)
35 #include <sys/types.h>
41 #if defined (__WIN32__) && ! defined (__CYGWIN__)
52 #if defined (HAVE_KILL)
56 octave_unused_parameter (pid);
57 octave_unused_parameter (
signum);
72 #if defined (HAVE_KILL)
86 if (!
strcmp (signame,
"SIGINT"))
93 else if (!
strcmp (signame,
"SIGBREAK"))
95 #if defined (SIGBREAK)
100 else if (!
strcmp (signame,
"SIGABRT"))
102 #if defined (SIGABRT)
107 else if (!
strcmp (signame,
"SIGALRM"))
109 #if defined (SIGALRM)
114 else if (!
strcmp (signame,
"SIGBUS"))
121 else if (!
strcmp (signame,
"SIGCHLD"))
123 #if defined (SIGCHLD)
128 else if (!
strcmp (signame,
"SIGCLD"))
135 else if (!
strcmp (signame,
"SIGCONT"))
137 #if defined (SIGCONT)
142 else if (!
strcmp (signame,
"SIGEMT"))
149 else if (!
strcmp (signame,
"SIGFPE"))
156 else if (!
strcmp (signame,
"SIGHUP"))
163 else if (!
strcmp (signame,
"SIGILL"))
170 else if (!
strcmp (signame,
"SIGINFO"))
172 #if defined (SIGINFO)
177 else if (!
strcmp (signame,
"SIGIOT"))
184 else if (!
strcmp (signame,
"SIGKILL"))
186 #if defined (SIGKILL)
191 else if (!
strcmp (signame,
"SIGLOST"))
193 #if defined (SIGLOST)
198 else if (!
strcmp (signame,
"SIGPIPE"))
200 #if defined (SIGPIPE)
205 else if (!
strcmp (signame,
"SIGPOLL"))
207 #if defined (SIGPOLL)
212 else if (!
strcmp (signame,
"SIGPROF"))
214 #if defined (SIGPROF)
219 else if (!
strcmp (signame,
"SIGPWR"))
226 else if (!
strcmp (signame,
"SIGQUIT"))
228 #if defined (SIGQUIT)
233 else if (!
strcmp (signame,
"SIGSEGV"))
235 #if defined (SIGSEGV)
240 else if (!
strcmp (signame,
"SIGSTOP"))
242 #if defined (SIGSTOP)
247 else if (!
strcmp (signame,
"SIGSYS"))
254 else if (!
strcmp (signame,
"SIGTERM"))
256 #if defined (SIGTERM)
261 else if (!
strcmp (signame,
"SIGTRAP"))
263 #if defined (SIGTRAP)
268 else if (!
strcmp (signame,
"SIGTSTP"))
270 #if defined (SIGTSTP)
275 else if (!
strcmp (signame,
"SIGTTIN"))
277 #if defined (SIGTTIN)
282 else if (!
strcmp (signame,
"SIGTTOU"))
284 #if defined (SIGTTOU)
289 else if (!
strcmp (signame,
"SIGURG"))
296 else if (!
strcmp (signame,
"SIGUSR1"))
298 #if defined (SIGUSR1)
303 else if (!
strcmp (signame,
"SIGUSR2"))
305 #if defined (SIGUSR2)
310 else if (!
strcmp (signame,
"SIGVTALRM"))
312 #if defined (SIGVTALRM)
317 else if (!
strcmp (signame,
"SIGIO"))
324 else if (!
strcmp (signame,
"SIGWINCH"))
326 #if defined (SIGWINCH)
331 else if (!
strcmp (signame,
"SIGXCPU"))
333 #if defined (SIGXCPU)
338 else if (!
strcmp (signame,
"SIGXFSZ"))
340 #if defined (SIGXFSZ)
351 bool restart_syscalls)
353 struct sigaction act, oact;
355 act.sa_handler = handler;
358 #if defined (SIGALRM)
361 # if defined (SA_INTERRUPT)
362 act.sa_flags |= SA_INTERRUPT;
366 #if defined (SA_RESTART)
367 # if defined (SIGALRM)
371 if (restart_syscalls)
372 act.sa_flags |= SA_RESTART;
375 sigemptyset (&act.sa_mask);
376 sigemptyset (&oact.sa_mask);
378 sigaction (sig, &act, &oact);
380 return oact.sa_handler;
386 bool restart_syscalls)
422 #if defined (SIGCHLD) || defined (SIGCLD)
428 sigemptyset (&(
context->ovar));
429 sigemptyset (&(
context->nvar));
430 #if defined (SIGCHLD)
431 sigaddset (&(
context->nvar), SIGCHLD);
434 sigaddset (&(
context->nvar), SIGCLD);
455 sigprocmask (SIG_SETMASK, &(
context->ovar), 0);
464 #if ! defined (__WIN32__) || defined (__CYGWIN__)
473 sigset_t signal_mask;
475 sigemptyset (&signal_mask);
477 sigaddset (&signal_mask, sig);
479 pthread_sigmask (how, &signal_mask, 0);
483 octave_unused_parameter (how);
484 octave_unused_parameter (sig);
494 #if defined (SIGBREAK)
504 #if defined (SIGBREAK)
555 return malloc (
sizeof (sigset_t));
567 sigprocmask (0, 0, mask);
573 sigprocmask (SIG_SETMASK, (sigset_t *) mask, 0);
576 #if ! defined (__WIN32__)
577 static const sigset_t *
580 static bool initialized =
false;
581 static sigset_t sigmask;
585 sigemptyset (&sigmask);
593 sigaddset (&sigmask, SIGINT);
596 #if defined (SIGBREAK)
597 sigaddset (&sigmask, SIGBREAK);
603 sigaddset (&sigmask, SIGHUP);
606 #if defined (SIGQUIT)
607 sigaddset (&sigmask, SIGQUIT);
610 #if defined (SIGTERM)
611 sigaddset (&sigmask, SIGTERM);
616 #if defined (SIGALRM)
617 sigaddset (&sigmask, SIGALRM);
620 #if defined (SIGVTALRM)
621 sigaddset (&sigmask, SIGVTALRM);
626 #if defined (SIGLOST)
627 sigaddset (&sigmask, SIGLOST);
630 #if defined (SIGPIPE)
631 sigaddset (&sigmask, SIGPIPE);
636 #if defined (SIGCHLD)
637 sigaddset (&sigmask, SIGCHLD);
641 sigaddset (&sigmask, SIGCLD);
646 #if defined (SIGXCPU)
647 sigaddset (&sigmask, SIGXCPU);
650 #if defined (SIGXFSZ)
651 sigaddset (&sigmask, SIGXFSZ);
664 #if ! defined (__WIN32__) || defined (__CYGWIN__)
672 #if ! defined (__WIN32__) || defined (__CYGWIN__)
683 #if ! defined (__WIN32__)
697 if (sigwait (async_signals, &sig_caught))
704 (*handler) (sig_caught);
712 #if ! defined (__WIN32__)
713 pthread_t sighandler_thread_id;
715 if (pthread_create (&sighandler_thread_id, 0,
signal_watcher, handler))
723 octave_unused_parameter (handler);
727 #if ! defined (__WIN32__)
734 for (sig = 1; sig < NSIG; sig++)
736 if (sigismember (sigset, sig))
739 fprintf (of,
"%ld: %s%d (%s)\n", (
long int) pthread_self (),
740 prefix, sig, strsignal (sig));
745 fprintf (of,
"%ld: %s<empty signal set>\n", (
long int) pthread_self (),
755 fprintf (of,
"%s", msg);
757 if (pthread_sigmask (SIG_BLOCK, NULL, &sigmask) == -1)
769 #if ! defined (__WIN32__)
771 msg =
"signal mask\n";
775 octave_unused_parameter (msg);
777 fputs (
"no signal mask on Windows systems\n", stderr);
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
int kill(pid_t pid, int sig)
static llvm::LLVMContext & context
void octave_save_signal_mask(void)
void octave_block_interrupt_signal(void)
void octave_create_interrupt_watcher_thread(octave_sig_handler *handler)
static void print_sigset(FILE *of, const char *prefix, const sigset_t *sigset)
octave_sig_handler * octave_set_default_signal_handler(int sig)
int octave_num_signals(void)
void octave_block_signal_by_name(const char *signame)
void * octave_block_child(void)
void octave_unblock_signal_by_name(const char *signame)
char * octave_strsignal_wrapper(int signum)
void octave_show_sigmask(const char *msg)
void octave_set_signal_mask(void *mask)
void octave_free_signal_mask(void *mask)
void octave_unblock_child(void *context_arg)
bool octave_get_sig_number(const char *signame, int *signum)
void octave_get_signal_mask(void *mask)
static void block_or_unblock_signal_by_name(int how, const char *signame)
int octave_kill_wrapper(pid_t pid, int signum)
octave_sig_handler * octave_set_default_signal_handler_by_name(const char *signame)
static void block_or_unblock_signal(int how, int sig)
void octave_unblock_async_signals(void)
static sigset_t octave_signal_mask
void octave_restore_signal_mask(void)
void octave_unblock_interrupt_signal(void)
void octave_block_async_signals(void)
static void * signal_watcher(void *arg)
bool octave_have_kill(void)
static const sigset_t * octave_async_signals(void)
int octave_raise_wrapper(int signum)
static int print_sigmask(FILE *of, const char *msg)
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)
void * octave_alloc_signal_mask(void)
void octave_sig_handler(int)