#include <signal.h>#include "utility.h"
Go to the source code of this file.
Defines | |
| #define | gs_do_setup(s, f) |
Functions | |
| Sigfunc * | gs_signal (int signo, Sigfunc *func) |
| int | gs_setup_signal_handlers (Sigfunc *func) |
Signal handling code for GridSolve.
Definition in file gs_signal.c.
| #define gs_do_setup | ( | s, | |||
| f | ) |
if(gs_signal(s, f) == SIG_ERR) { \ failure_seen = 1; \ ERRPRINTF("Warning: could not set up signal handler (sig = %d)\n",s); \ }
| int gs_setup_signal_handlers | ( | Sigfunc * | func | ) |
Register the specified function as a signal handler for lots of different signals.
| func | -- the signal handler |
Definition at line 67 of file gs_signal.c.
{
int failure_seen = 0;
#define gs_do_setup(s, f) \
if(gs_signal(s, f) == SIG_ERR) { \
failure_seen = 1; \
ERRPRINTF("Warning: could not set up signal handler (sig = %d)\n",s); \
}
#ifdef SIGHUP
gs_do_setup(SIGHUP, func);
#endif
#ifdef SIGINT
gs_do_setup(SIGINT, func);
#endif
#ifdef SIGQUIT
gs_do_setup(SIGQUIT, func);
#endif
#ifdef SIGILL
gs_do_setup(SIGILL, func);
#endif
#ifdef SIGTRAP
gs_do_setup(SIGTRAP, func);
#endif
#ifdef SIGABRT
gs_do_setup(SIGABRT, func);
#endif
#ifdef SIGEMT
gs_do_setup(SIGEMT, func);
#endif
#ifdef SIGFPE
gs_do_setup(SIGFPE, func);
#endif
#ifdef SIGBUS
gs_do_setup(SIGBUS, func);
#endif
#ifdef SIGSEGV
gs_do_setup(SIGSEGV, func);
#endif
#ifdef SIGSYS
gs_do_setup(SIGSYS, func);
#endif
#ifdef SIGPIPE
gs_do_setup(SIGPIPE, func);
#endif
#ifdef SIGALRM
gs_do_setup(SIGALRM, func);
#endif
#ifdef SIGTERM
gs_do_setup(SIGTERM, func);
#endif
#ifdef SIGTSTP
gs_do_setup(SIGTSTP, func);
#endif
#ifdef SIGTTIN
gs_do_setup(SIGTTIN, func);
#endif
#ifdef SIGTTOU
gs_do_setup(SIGTTOU, func);
#endif
#ifdef SIGXCPU
gs_do_setup(SIGXCPU, func);
#endif
#ifdef SIGXFSZ
gs_do_setup(SIGXFSZ, func);
#endif
#ifdef SIGVTALRM
gs_do_setup(SIGVTALRM, func);
#endif
#ifdef SIGPROF
gs_do_setup(SIGPROF, func);
#endif
#ifdef SIGUSR1
gs_do_setup(SIGUSR1, func);
#endif
#ifdef SIGUSR2
gs_do_setup(SIGUSR2, func);
#endif
return failure_seen;
}

| Sigfunc* gs_signal | ( | int | signo, | |
| Sigfunc * | func | |||
| ) |
This is a wrapper around sigaction that sets the SA_RESTART flag so that system calls are restarted after being interrupted. This code was taken from page 120 of "Unix Network Programming" by W. Richard Stevens.
| signal | -- the signal number that should be handled | |
| func | -- the function to be called when the specified signal is caught |
Definition at line 28 of file gs_signal.c.
{
#ifdef WIN32
signal(signo, func);
return func;
#else
struct sigaction act, oact;
act.sa_handler = func;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (signo == SIGALRM) {
#ifdef SA_INTERRUPT
act.sa_flags |= SA_INTERRUPT; /* SunOS 4.x */
#endif
} else {
#ifdef SA_RESTART
act.sa_flags |= SA_RESTART; /* SVR4, 44BSD */
#endif
}
if(sigaction(signo, &act, &oact) < 0)
return(SIG_ERR);
return(oact.sa_handler);
#endif /* ifdef WIN32 */
}

1.6.3-20100507