1 |
edhill |
1.1 |
/* |
2 |
edhill |
1.2 |
* $Header: /u/gcmpack/MITgcm/eesupp/src/sigreg.c,v 1.1 2005/12/03 08:30:32 edhill Exp $ |
3 |
edhill |
1.1 |
* $Name: $ |
4 |
|
|
|
5 |
|
|
//BOP |
6 |
|
|
// !ROUTINE: sigreg |
7 |
|
|
// !INTERFACE: |
8 |
|
|
sigreg() |
9 |
|
|
|
10 |
|
|
// !DESCRIPTION: |
11 |
|
|
// Register a signal handler |
12 |
|
|
|
13 |
|
|
//EOP |
14 |
|
|
|
15 |
|
|
*/ |
16 |
|
|
|
17 |
|
|
/* Here, we get the definition of the FC_NAMEMANGLE() macro. */ |
18 |
|
|
#include "FC_NAMEMANGLE.h" |
19 |
|
|
|
20 |
|
|
/* #define FC_NAMEMANGLE(X) X ## _ */ |
21 |
|
|
|
22 |
|
|
#include <stdlib.h> |
23 |
|
|
#include <stdio.h> |
24 |
|
|
#include <signal.h> |
25 |
|
|
#include <errno.h> |
26 |
|
|
#include <ucontext.h> |
27 |
|
|
|
28 |
|
|
int * ip; |
29 |
|
|
|
30 |
|
|
static void killhandler( |
31 |
|
|
unsigned int sn, siginfo_t si, struct ucontext *sc ) |
32 |
|
|
{ |
33 |
|
|
*ip = *ip + 1; |
34 |
|
|
return; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
/* int main( int argc, char ** argv ) */ |
38 |
|
|
void FC_NAMEMANGLE(sigreg) (int * aip) |
39 |
|
|
{ |
40 |
edhill |
1.2 |
struct sigaction s; |
41 |
edhill |
1.1 |
ip = aip; |
42 |
|
|
s.sa_flags = SA_SIGINFO; |
43 |
|
|
s.sa_sigaction = (void *)killhandler; |
44 |
|
|
if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) { |
45 |
|
|
printf("Sigaction returned error = %d\n", errno); |
46 |
|
|
exit(0); |
47 |
|
|
} |
48 |
|
|
return; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
|