31 #if defined (HAVE_CONFIG_H)
35 #include <sys/types.h>
41 #if defined (__WIN32__) && ! defined (__CYGWIN__)
52 #if defined (HAVE_KILL)
54 #elif defined (HAVE_RAISE)
55 octave_unused_parameter (pid);
59 octave_unused_parameter (pid);
60 octave_unused_parameter (
signum);
75 #if defined (HAVE_KILL)
89 if (!
strcmp (signame,
"SIGINT"))
96 else if (!
strcmp (signame,
"SIGBREAK"))
98 #if defined (SIGBREAK)
103 else if (!
strcmp (signame,
"SIGABRT"))
105 #if defined (SIGABRT)
110 else if (!
strcmp (signame,
"SIGALRM"))
112 #if defined (SIGALRM)
117 else if (!
strcmp (signame,
"SIGBUS"))
124 else if (!
strcmp (signame,
"SIGCHLD"))
126 #if defined (SIGCHLD)
131 else if (!
strcmp (signame,
"SIGCLD"))
138 else if (!
strcmp (signame,
"SIGCONT"))
140 #if defined (SIGCONT)
145 else if (!
strcmp (signame,
"SIGEMT"))
152 else if (!
strcmp (signame,
"SIGFPE"))
159 else if (!
strcmp (signame,
"SIGHUP"))
166 else if (!
strcmp (signame,
"SIGILL"))
173 else if (!
strcmp (signame,
"SIGINFO"))
175 #if defined (SIGINFO)
180 else if (!
strcmp (signame,
"SIGIOT"))
187 else if (!
strcmp (signame,
"SIGKILL"))
189 #if defined (SIGKILL)
194 else if (!
strcmp (signame,
"SIGLOST"))
196 #if defined (SIGLOST)
201 else if (!
strcmp (signame,
"SIGPIPE"))
203 #if defined (SIGPIPE)
208 else if (!
strcmp (signame,
"SIGPOLL"))
210 #if defined (SIGPOLL)
215 else if (!
strcmp (signame,
"SIGPROF"))
217 #if defined (SIGPROF)
222 else if (!
strcmp (signame,
"SIGPWR"))
229 else if (!
strcmp (signame,
"SIGQUIT"))
231 #if defined (SIGQUIT)
236 else if (!
strcmp (signame,
"SIGSEGV"))
238 #if defined (SIGSEGV)
243 else if (!
strcmp (signame,
"SIGSTOP"))
245 #if defined (SIGSTOP)
250 else if (!
strcmp (signame,
"SIGSYS"))
257 else if (!
strcmp (signame,
"SIGTERM"))
259 #if defined (SIGTERM)
264 else if (!
strcmp (signame,
"SIGTRAP"))
266 #if defined (SIGTRAP)
271 else if (!
strcmp (signame,
"SIGTSTP"))
273 #if defined (SIGTSTP)
278 else if (!
strcmp (signame,
"SIGTTIN"))
280 #if defined (SIGTTIN)
285 else if (!
strcmp (signame,
"SIGTTOU"))
287 #if defined (SIGTTOU)
292 else if (!
strcmp (signame,
"SIGURG"))
299 else if (!
strcmp (signame,
"SIGUSR1"))
301 #if defined (SIGUSR1)
306 else if (!
strcmp (signame,
"SIGUSR2"))
308 #if defined (SIGUSR2)
313 else if (!
strcmp (signame,
"SIGVTALRM"))
315 #if defined (SIGVTALRM)
320 else if (!
strcmp (signame,
"SIGIO"))
327 else if (!
strcmp (signame,
"SIGWINCH"))
329 #if defined (SIGWINCH)
334 else if (!
strcmp (signame,
"SIGXCPU"))
336 #if defined (SIGXCPU)
341 else if (!
strcmp (signame,
"SIGXFSZ"))
343 #if defined (SIGXFSZ)
354 bool restart_syscalls)
356 struct sigaction act, oact;
358 act.sa_handler = handler;
361 #if defined (SIGALRM)
364 # if defined (SA_INTERRUPT)
365 act.sa_flags |= SA_INTERRUPT;
369 #if defined (SA_RESTART)
370 # if defined (SIGALRM)
374 if (restart_syscalls)
375 act.sa_flags |= SA_RESTART;
378 sigemptyset (&act.sa_mask);
379 sigemptyset (&oact.sa_mask);
381 sigaction (sig, &act, &oact);
383 return oact.sa_handler;
389 bool restart_syscalls)
425 #if defined (SIGCHLD) || defined (SIGCLD)
427 sigset_info *context = (sigset_info *)
malloc (
sizeof (sigset_info));
431 sigemptyset (&(context->ovar));
432 sigemptyset (&(context->nvar));
433 #if defined (SIGCHLD)
434 sigaddset (&(context->nvar), SIGCHLD);
437 sigaddset (&(context->nvar), SIGCLD);
439 sigprocmask (SIG_BLOCK, &(context->nvar), &(context->ovar));
456 sigset_info *context = (sigset_info *) context_arg;
458 sigprocmask (SIG_SETMASK, &(context->ovar), 0);
465 block_or_unblock_signal (
int how,
int sig)
467 #if ! defined (__WIN32__) || defined (__CYGWIN__)
476 sigset_t signal_mask;
478 sigemptyset (&signal_mask);
480 sigaddset (&signal_mask, sig);
482 pthread_sigmask (how, &signal_mask, 0);
486 octave_unused_parameter (how);
487 octave_unused_parameter (sig);
495 block_or_unblock_signal (SIG_BLOCK, SIGINT);
497 #if defined (SIGBREAK)
498 block_or_unblock_signal (SIG_BLOCK, SIGBREAK);
505 block_or_unblock_signal (SIG_UNBLOCK, SIGINT);
507 #if defined (SIGBREAK)
508 block_or_unblock_signal (SIG_UNBLOCK, SIGBREAK);
513 block_or_unblock_signal_by_name (
int how,
const char *signame)
518 block_or_unblock_signal (how, sig);
524 block_or_unblock_signal_by_name (SIG_BLOCK, signame);
530 block_or_unblock_signal_by_name (SIG_UNBLOCK, signame);
541 static sigset_t octave_signal_mask;
546 sigprocmask (0, 0, &octave_signal_mask);
552 sigprocmask (SIG_SETMASK, &octave_signal_mask, 0);
558 return malloc (
sizeof (sigset_t));
570 sigprocmask (0, 0, mask);
576 sigprocmask (SIG_SETMASK, (sigset_t *) mask, 0);
585 #if ! defined (__WIN32__)
587 print_sigset (FILE *of,
const char *prefix,
const sigset_t *sigset)
592 for (sig = 1; sig < NSIG; sig++)
594 if (sigismember (sigset, sig))
597 fprintf (of,
"%ld: %s%d (%s)\n", (
long int) pthread_self (),
598 prefix, sig, strsignal (sig));
603 fprintf (of,
"%ld: %s<empty signal set>\n", (
long int) pthread_self (),
608 print_sigmask (FILE *of,
const char *msg)
613 fprintf (of,
"%s", msg);
615 if (pthread_sigmask (SIG_BLOCK, NULL, &sigmask) == -1)
618 print_sigset (of,
"\t\t", &sigmask);
627 #if ! defined (__WIN32__)
629 msg =
"signal mask\n";
631 print_sigmask (stderr, msg);
633 octave_unused_parameter (msg);
635 fputs (
"no signal mask on Windows systems\n", stderr);
bool strcmp(const T &str_a, const T &str_b)
Octave string utility functions.
int kill(pid_t pid, int sig)
void octave_save_signal_mask(void)
void octave_block_interrupt_signal(void)
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)
int octave_kill_wrapper(pid_t pid, int signum)
octave_sig_handler * octave_set_default_signal_handler_by_name(const char *signame)
void octave_restore_signal_mask(void)
void octave_unblock_interrupt_signal(void)
bool octave_have_kill(void)
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)
void * octave_alloc_signal_mask(void)
void octave_sig_handler(int)