Octopus
signals.c
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 X. Andrade
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18
19*/
20
21#include <config.h>
22#include <signal.h>
23#include <fortran_types.h>
24#include <stdlib.h>
25#include <string.h>
26
27#if __has_include(<unistd.h>)
28#include <unistd.h>
29#endif
30
31void FC_FUNC_(block_signals, BLOCK_SIGNALS)() {
32#ifdef _POSIX_VERSION
33 struct sigaction act;
34
35 act.sa_handler = SIG_IGN;
36 sigemptyset(&act.sa_mask);
37 act.sa_flags = 0;
38
39 sigaction(SIGINT, &act, 0);
40 sigaction(SIGTERM, &act, 0);
41#endif
42}
43
44void FC_FUNC_(unblock_signals, UNBLOCK_SIGNALS)() {
45#ifdef _POSIX_VERSION
46 struct sigaction act;
47
48 act.sa_handler = SIG_DFL;
49 sigemptyset(&act.sa_mask);
50 act.sa_flags = 0;
51
52 sigaction(SIGINT, &act, 0);
53 sigaction(SIGTERM, &act, 0);
54
55#endif
58void handle_segv(int *);
59
60#ifdef _POSIX_VERSION
62void segv_handler(int signum, siginfo_t *si, void *vd) {
63 handle_segv(&signum);
64 signal(signum, SIG_DFL);
65 kill(getpid(), signum);
67
68#endif
70void FC_FUNC_(trap_segfault, TRAP_SEGFAULT)() {
71#ifdef _POSIX_VERSION
72 struct sigaction act;
73
74 sigemptyset(&act.sa_mask);
75 act.sa_sigaction = segv_handler;
76 act.sa_flags = SA_SIGINFO;
78 sigaction(SIGTERM, &act, 0);
79 sigaction(SIGKILL, &act, 0);
80 sigaction(SIGSEGV, &act, 0);
81 sigaction(SIGABRT, &act, 0);
82 sigaction(SIGINT, &act, 0);
83 sigaction(SIGBUS, &act, 0);
84 sigaction(SIGILL, &act, 0);
85 sigaction(SIGTSTP, &act, 0);
86 sigaction(SIGQUIT, &act, 0);
87 sigaction(SIGFPE, &act, 0);
88 sigaction(SIGHUP, &act, 0);
89
90#endif
91}
92
93void get_signal_description(fint *signum, char * signame) {
94#ifdef _POSIX_VERSION
95 strcpy(signame, strsignal(*signum));
96#else
97 strcpy(signame, "(description not available)");
98#endif
99}
int fint
Definition: fortran_types.h:14
void segv_handler(int signum, siginfo_t *si, void *vd)
Definition: signals.c:3689
void FC_FUNC_(unblock_signals, UNBLOCK_SIGNALS)()
Definition: signals.c:3655
__sighandler_t signal(int __sig, __sighandler_t __handler) __attribute__((__nothrow__
__pid_t getpid(void)
Definition: signals.c:3259
void get_signal_description(fint *signum, char *signame)
Definition: signals.c:3776
int kill(__pid_t __pid, int __sig) __attribute__((__nothrow__
int sigaction(int __sig, const struct sigaction *__restrict __act, struct sigaction *__restrict __oact) __attribute__((__nothrow__
void handle_segv(int *)