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