| 1 |
/* |
| 2 |
* $Header: /u/gcmpack/MITgcm/eesupp/src/sigreg.c,v 1.6 2007/07/31 22:48:34 ce107 Exp $ |
| 3 |
* $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 |
#ifdef HAVE_SIGREG |
| 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 |
#ifdef HAVE_SIGREG |
| 23 |
#include <stdlib.h> |
| 24 |
#include <stdio.h> |
| 25 |
#include <signal.h> |
| 26 |
#include <errno.h> |
| 27 |
#include <ucontext.h> |
| 28 |
|
| 29 |
int * sigreg_ip; |
| 30 |
|
| 31 |
static void killhandler( |
| 32 |
unsigned int sn, siginfo_t si, struct ucontext *sc ) |
| 33 |
{ |
| 34 |
*sigreg_ip = *sigreg_ip + 1; |
| 35 |
return; |
| 36 |
} |
| 37 |
#endif |
| 38 |
|
| 39 |
/* int main( int argc, char ** argv ) */ |
| 40 |
void FC_NAMEMANGLE(sigreg) (int * aip) |
| 41 |
{ |
| 42 |
#ifdef HAVE_SIGREG |
| 43 |
struct sigaction s; |
| 44 |
sigreg_ip = aip; |
| 45 |
s.sa_flags = SA_SIGINFO; |
| 46 |
s.sa_sigaction = (void *)killhandler; |
| 47 |
if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) { |
| 48 |
printf("Sigaction returned error = %d\n", errno); |
| 49 |
exit(0); |
| 50 |
} |
| 51 |
#endif |
| 52 |
return; |
| 53 |
} |
| 54 |
#endif |
| 55 |
|