-
Notifications
You must be signed in to change notification settings - Fork 15
/
signalqq.c
66 lines (45 loc) · 1.23 KB
/
signalqq.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* $Id: signalqq.c,v 1.3 2012/06/27 10:10:37 mjlaine Exp $ */
/* Gfortran signal handler for ctrl-c */
/* Part of the mcmc library */
/*
* Marko Laine 2008 <[email protected]>
* Copyrights licensed under a MIT License.
* See the accompanying LICENSE.txt file for terms.
*/
#ifdef WIN32
/* do nothing if using (mingw) gfortran in Windows */
void signalqq_(void (*handler)()){}
#else
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <signal.h>
void def_handler(int sig);
typedef void (* funptr)(int);
static funptr gf_handler = def_handler;
void sig_handler(int j, siginfo_t *info, void *dummy)
{
/* Call fortran handler given as argument to signalqq */
gf_handler(j);
}
/* The default signal handler */
void def_handler(int sig)
{
/* do nothing */
}
void signalqq_(void (*handler)())
{
struct sigaction act;
gf_handler = (*handler); /* save routine pointer to a static variable */
act.sa_sigaction=(*sig_handler);
sigemptyset(&act.sa_mask);
act.sa_flags=SA_SIGINFO;
sigaction(SIGHUP, &act, NULL);
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
sigaction(SIGTSTP, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
sigaction(SIGUSR2, &act, NULL);
}
#endif