Annotation of OpenXM/src/util/mysig.c, Revision 1.1
1.1 ! takayama 1: /* $OpenXM$
! 2: */
! 3: #include <stdio.h>
! 4: #include <signal.h>
! 5: #include <unistd.h>
! 6: #include <setjmp.h>
! 7: #include <string.h>
! 8: #include "mysig.h"
! 9:
! 10: static void *Old_handler;
! 11: /*
! 12: sigset SIGINT, SIGCHLD, SIGUSR1
! 13: */
! 14: int unblock_signal(int sigset[]) {
! 15: struct sigaction act;
! 16: sigset_t set;
! 17: sigset_t oldset;
! 18: int i;
! 19: sigemptyset(&set);
! 20: for (i=0; sigset[i] > 0; i++) sigaddset(&set,sigset[i]);
! 21: sigprocmask(SIG_UNBLOCK,&set,&oldset);
! 22: return(0);
! 23: }
! 24: /* Add (or) blocked signals, see sigprocmask */
! 25: int block_signal(int sigset[]) {
! 26: struct sigaction act;
! 27: sigset_t set;
! 28: sigset_t oldset;
! 29: int i;
! 30: sigemptyset(&set);
! 31: for (i=0; sigset[i] > 0; i++) sigaddset(&set,sigset[i]);
! 32: sigprocmask(SIG_BLOCK,&set,&oldset);
! 33: return(0);
! 34: }
! 35:
! 36: int set_signal(int sig,void (*handler)(int m)) {
! 37: struct sigaction act;
! 38: struct sigaction oldact;
! 39: int val;
! 40: act.sa_handler=handler;
! 41: act.sa_flags=0;
! 42: act.sa_flags |= SA_RESTART;
! 43: sigemptyset(&act.sa_mask);
! 44: val=sigaction(sig,&act,&oldact);
! 45: Old_handler = oldact.sa_handler;
! 46: return(val);
! 47: }
! 48: /*
! 49: my own emulation of signal for portability.
! 50: */
! 51: void *mysignal(int sig,void (*handler)(int m)) {
! 52: int sigset[2];
! 53: if (handler == SIG_IGN) {
! 54: /* sigset[0] = sig; sigset[1]=0;
! 55: block_signal(sigset);
! 56: return(SIG_IGN);*/
! 57: return(signal(sig,handler));
! 58: }else if (handler == SIG_DFL) {
! 59: return(signal(sig,handler));
! 60: }
! 61: /* on unix system, you may simply call signal(3) here. */
! 62: set_signal(sig,handler);
! 63: /* unblock is necessary on cygwin, ... */
! 64: sigset[0] = sig; sigset[1]=0; unblock_signal(sigset);
! 65: return((void *)Old_handler);
! 66: }
! 67:
! 68:
! 69:
! 70:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>