Annotation of OpenXM/src/ox_python/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: #if !defined(SA_RESTART) && defined(__FreeBSD__)
! 37: #define SA_RESTART 0x0002
! 38: #endif
! 39:
! 40: int set_signal(int sig,void (*handler)(int m)) {
! 41: struct sigaction act;
! 42: struct sigaction oldact;
! 43: int val;
! 44: act.sa_handler=handler;
! 45: act.sa_flags=0;
! 46: act.sa_flags |= SA_RESTART;
! 47: sigemptyset(&act.sa_mask);
! 48: val=sigaction(sig,&act,&oldact);
! 49: Old_handler = oldact.sa_handler;
! 50: return(val);
! 51: }
! 52: /*
! 53: my own emulation of signal for portability.
! 54: */
! 55: void *mysignal(int sig,void (*handler)(int m)) {
! 56: int sigset[2];
! 57: if (handler == SIG_IGN) {
! 58: /* sigset[0] = sig; sigset[1]=0;
! 59: block_signal(sigset);
! 60: return(SIG_IGN);*/
! 61: return(signal(sig,handler));
! 62: }else if (handler == SIG_DFL) {
! 63: return(signal(sig,handler));
! 64: }
! 65: /* on unix system, you may simply call signal(3) here. */
! 66: set_signal(sig,handler);
! 67: /* unblock is necessary on cygwin, ..., cf. misc-2015/12/misc */
! 68: sigset[0] = sig; sigset[1]=0; unblock_signal(sigset);
! 69: return((void *)Old_handler);
! 70: }
! 71:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>