Annotation of OpenXM/src/ox_pari/mysig.c, Revision 1.2
1.2 ! noro 1: /* $OpenXM: OpenXM/src/ox_pari/mysig.c,v 1.1 2018/06/04 06:28:05 ohara Exp $
1.1 ohara 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: sigset_t set;
16: sigset_t oldset;
17: int i;
18: sigemptyset(&set);
19: for (i=0; sigset[i] > 0; i++) sigaddset(&set,sigset[i]);
20: sigprocmask(SIG_UNBLOCK,&set,&oldset);
21: return(0);
22: }
23: /* Add (or) blocked signals, see sigprocmask */
24: int block_signal(int sigset[]) {
25: sigset_t set;
26: sigset_t oldset;
27: int i;
28: sigemptyset(&set);
29: for (i=0; sigset[i] > 0; i++) sigaddset(&set,sigset[i]);
30: sigprocmask(SIG_BLOCK,&set,&oldset);
31: return(0);
32: }
33:
34: #if !defined(SA_RESTART) && defined(__FreeBSD__)
35: #define SA_RESTART 0x0002
36: #endif
37:
38: int set_signal(int sig,void (*handler)(int m)) {
39: struct sigaction act;
40: struct sigaction oldact;
41: int val;
42: act.sa_handler=handler;
43: act.sa_flags=0;
44: act.sa_flags |= SA_RESTART;
45: sigemptyset(&act.sa_mask);
46: val=sigaction(sig,&act,&oldact);
47: Old_handler = oldact.sa_handler;
48: return(val);
49: }
50: /*
51: my own emulation of signal for portability.
52: */
53: void *mysignal(int sig,void (*handler)(int m)) {
54: int sigset[2];
55: if (handler == SIG_IGN) {
56: /* sigset[0] = sig; sigset[1]=0;
57: block_signal(sigset);
58: return(SIG_IGN);*/
59: return(signal(sig,handler));
60: }else if (handler == SIG_DFL) {
61: return(signal(sig,handler));
62: }
63: /* on unix system, you may simply call signal(3) here. */
64: set_signal(sig,handler);
65: /* unblock is necessary on cygwin, ..., cf. misc-2015/12/misc */
66: sigset[0] = sig; sigset[1]=0; unblock_signal(sigset);
67: return((void *)Old_handler);
68: }
69:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>