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 "string_f.h" /* fortran <-> c string compatibility issues */
24#include <fortran_types.h>
25#include <stdlib.h>
26#include <string.h>
27
28#if __has_include(<unistd.h>)
29#include <unistd.h>
30#endif
31
32void FC_FUNC_(block_signals, BLOCK_SIGNALS)() {
33#ifdef _POSIX_VERSION
34 struct sigaction act;
35
36 act.sa_handler = SIG_IGN;
37 sigemptyset(&act.sa_mask);
38 act.sa_flags = 0;
39
40 sigaction(SIGINT, &act, 0);
41 sigaction(SIGTERM, &act, 0);
42#endif
43}
44
45void FC_FUNC_(unblock_signals, UNBLOCK_SIGNALS)() {
46#ifdef _POSIX_VERSION
47 struct sigaction act;
48
49 act.sa_handler = SIG_DFL;
50 sigemptyset(&act.sa_mask);
51 act.sa_flags = 0;
52
53 sigaction(SIGINT, &act, 0);
54 sigaction(SIGTERM, &act, 0);
56#endif
59void handle_segv(int *);
60
61#ifdef _POSIX_VERSION
63void segv_handler(int signum, siginfo_t *si, void *vd) {
64 handle_segv(&signum);
65 signal(signum, SIG_DFL);
66 kill(getpid(), signum);
67}
69#endif
70
71void FC_FUNC_(trap_segfault, TRAP_SEGFAULT)() {
72#ifdef _POSIX_VERSION
73 struct sigaction act;
74
75 sigemptyset(&act.sa_mask);
76 act.sa_sigaction = segv_handler;
77 act.sa_flags = SA_SIGINFO;
79 sigaction(SIGTERM, &act, 0);
80 sigaction(SIGKILL, &act, 0);
81 sigaction(SIGSEGV, &act, 0);
82 sigaction(SIGABRT, &act, 0);
83 sigaction(SIGINT, &act, 0);
84 sigaction(SIGBUS, &act, 0);
85 sigaction(SIGILL, &act, 0);
86 sigaction(SIGTSTP, &act, 0);
87 sigaction(SIGQUIT, &act, 0);
88 sigaction(SIGFPE, &act, 0);
89 sigaction(SIGHUP, &act, 0);
90
91#endif
92}
93
94void FC_FUNC_(get_signal_description,
95 GET_SIGNAL_DESCRIPTION)(fint *signum,
96 STR_F_TYPE const signame STR_ARG1) {
97#ifdef _POSIX_VERSION
98 TO_F_STR1(strsignal(*signum), signame);
99#else
100 TO_F_STR1("(description not available)", signame);
101#endif
102}
int fint
Definition: fortran_types.h:14
void segv_handler(int signum, siginfo_t *si, void *vd)
Definition: signals.c:3693
__sighandler_t signal(int __sig, __sighandler_t __handler) __attribute__((__nothrow__
__pid_t getpid(void)
Definition: signals.c:3263
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 *)