version 1.1, 2016/03/30 08:25:43 |
version 1.4, 2016/03/31 03:22:55 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/kan96xx/plugin/mysig.c,v 1.3 2016/03/30 21:34:03 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include <signal.h> |
#include <signal.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
#include <string.h> |
#include <string.h> |
#include "mysig.h" |
#include "mysig.h" |
|
|
int unblock_sigchild_sigint(void) { |
static void *Old_handler; |
|
/* |
|
sigset SIGINT, SIGCHLD, SIGUSR1 |
|
*/ |
|
int unblock_signal(int sigset[]) { |
struct sigaction act; |
struct sigaction act; |
sigset_t set; |
sigset_t set; |
sigset_t oldset; |
sigset_t oldset; |
|
int i; |
sigemptyset(&set); |
sigemptyset(&set); |
sigaddset(&set,SIGINT); |
for (i=0; sigset[i] > 0; i++) sigaddset(&set,sigset[i]); |
sigaddset(&set,SIGCHLD); |
|
sigprocmask(SIG_UNBLOCK,&set,&oldset); |
sigprocmask(SIG_UNBLOCK,&set,&oldset); |
return(0); |
return(0); |
} |
} |
|
/* Add (or) blocked signals, see sigprocmask */ |
|
int block_signal(int sigset[]) { |
|
struct sigaction act; |
|
sigset_t set; |
|
sigset_t oldset; |
|
int i; |
|
sigemptyset(&set); |
|
for (i=0; sigset[i] > 0; i++) sigaddset(&set,sigset[i]); |
|
sigprocmask(SIG_BLOCK,&set,&oldset); |
|
return(0); |
|
} |
|
|
int set_sigchild(void (*handler)(void)) { |
int set_signal(int sig,void (*handler)(int m)) { |
struct sigaction act; |
struct sigaction act; |
struct sigaction oldact; |
struct sigaction oldact; |
|
int val; |
act.sa_handler=handler; |
act.sa_handler=handler; |
act.sa_flags=0; |
act.sa_flags=0; |
act.sa_flags |= SA_RESTART; |
act.sa_flags |= SA_RESTART; |
sigemptyset(&act.sa_mask); |
sigemptyset(&act.sa_mask); |
return(sigaction(SIGCHLD,&act,&oldact)); |
val=sigaction(sig,&act,&oldact); |
|
Old_handler = oldact.sa_handler; |
|
return(val); |
|
} |
|
/* |
|
my own emulation of signal for portability. |
|
*/ |
|
void *mysignal(int sig,void (*handler)(int m)) { |
|
int sigset[2]; |
|
if (handler == SIG_IGN) { |
|
/* sigset[0] = sig; sigset[1]=0; |
|
block_signal(sigset); |
|
return(SIG_IGN);*/ |
|
return(signal(sig,handler)); |
|
}else if (handler == SIG_DFL) { |
|
return(signal(sig,handler)); |
|
} |
|
/* on unix system, you may simply call signal(3) here. */ |
|
set_signal(sig,handler); |
|
/* unblock is necessary on cygwin, ... */ |
|
sigset[0] = sig; sigset[1]=0; unblock_signal(sigset); |
|
return((void *)Old_handler); |
} |
} |
|
|
|
|