Index: configure.ac =================================================================== RCS file: /home/nisse/.cvsroot/liboop/configure.ac,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- configure.ac 24 Nov 2004 21:00:03 -0000 1.1.1.1 +++ configure.ac 24 Nov 2004 22:00:04 -0000 1.2 @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(INSTALL) -AM_INIT_AUTOMAKE(liboop,1.0) +AM_INIT_AUTOMAKE(liboop,1.0-nisse1) AC_CANONICAL_HOST AM_PROG_LIBTOOL AC_PROG_CC Index: oop.h =================================================================== RCS file: /home/nisse/.cvsroot/liboop/oop.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- oop.h 24 Nov 2004 20:59:54 -0000 1.1.1.1 +++ oop.h 24 Nov 2004 22:00:04 -0000 1.2 @@ -85,6 +85,9 @@ /* Get the event registration interface for a system event source. */ oop_source *oop_sys_source(oop_source_sys *); +/* Set flags to be used for sigaction. */ +void oop_sys_set_sa_flags(oop_source_sys *, int); + /* ------------------------------------------------------------------------- */ /* Helper for select-style asynchronous interfaces. */ @@ -114,4 +117,5 @@ void oop_signal_delete(oop_adapter_signal *); oop_source *oop_signal_source(oop_adapter_signal *); +void oop_signal_set_sa_flags(oop_adapter_signal *, int); #endif Index: signal.c =================================================================== RCS file: /home/nisse/.cvsroot/liboop/signal.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- signal.c 24 Nov 2004 21:00:05 -0000 1.1.1.1 +++ signal.c 24 Nov 2004 22:00:04 -0000 1.2 @@ -30,6 +30,7 @@ oop_source oop; int magic,pipefd[2]; oop_source *source; /* backing source */ + int sa_flags; struct sig_signal sig[OOP_NUM_SIGNALS]; int num_events; }; @@ -49,14 +50,8 @@ static void on_signal(int sig) { oop_adapter_signal * const s = sig_owner[sig]; - struct sigaction act; assert(NULL != s); - /* Reset the handler, in case this is needed. */ - sigaction(sig,NULL,&act); - act.sa_handler = on_signal; - sigaction(sig,&act,NULL); - assert(NULL != s->sig[sig].list); s->sig[sig].active = 1; do_pipe(s); @@ -137,6 +132,7 @@ #ifdef SA_NODEFER act.sa_flags &= ~SA_NODEFER; #endif + act.sa_flags |= s->sa_flags; sigaction(sig,&act,NULL); } } @@ -178,11 +174,17 @@ oop_adapter_signal * const s = oop_malloc(sizeof(*s)); if (NULL == s) return NULL; assert(NULL != source); - if (pipe(s->pipefd) - || fcntl_flag(s->pipefd[0],F_GETFD,F_SETFD,FD_CLOEXEC) + if (pipe(s->pipefd)) { + oop_free(s); + return NULL; + } + + if (fcntl_flag(s->pipefd[0],F_GETFD,F_SETFD,FD_CLOEXEC) || fcntl_flag(s->pipefd[1],F_GETFD,F_SETFD,FD_CLOEXEC) || fcntl_flag(s->pipefd[0],F_GETFL,F_SETFL,O_NONBLOCK) || fcntl_flag(s->pipefd[1],F_GETFL,F_SETFL,O_NONBLOCK)) { + close(s->pipefd[0]); + close(s->pipefd[1]); oop_free(s); return NULL; } @@ -198,6 +200,7 @@ s->source->on_fd(s->source,s->pipefd[0],OOP_READ,on_pipe,s); s->num_events = 0; + s->sa_flags = 0; for (i = 0; i < OOP_NUM_SIGNALS; ++i) { s->sig[i].list = NULL; s->sig[i].ptr = NULL; @@ -219,4 +222,8 @@ oop_source *oop_signal_source(oop_adapter_signal *s) { return &s->oop; +} + +void oop_signal_set_sa_flags(oop_adapter_signal *s, int flags) { + s->sa_flags = flags; } Index: sys.c =================================================================== RCS file: /home/nisse/.cvsroot/liboop/sys.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- sys.c 24 Nov 2004 21:00:05 -0000 1.1.1.1 +++ sys.c 24 Nov 2004 22:00:04 -0000 1.2 @@ -70,6 +70,7 @@ struct sys_time *time_queue,*time_run; /* Signal handling */ + int sa_flags; struct sys_signal sig[OOP_NUM_SIGNALS]; sigjmp_buf env; int do_jmp,sig_active; @@ -79,7 +80,7 @@ sys_file *files; }; -struct oop_source_sys *sys_sig_owner[OOP_NUM_SIGNALS]; +static oop_source_sys *sys_sig_owner[OOP_NUM_SIGNALS]; static oop_source_sys *verify_source(oop_source *source) { oop_source_sys *sys = (oop_source_sys *) source; @@ -177,14 +178,8 @@ static void sys_signal_handler(int sig) { oop_source_sys *sys = sys_sig_owner[sig]; - struct sigaction act; assert(NULL != sys); - /* Reset the handler, in case this is needed. */ - sigaction(sig,NULL,&act); - act.sa_handler = sys_signal_handler; - sigaction(sig,&act,NULL); - assert(NULL != sys->sig[sig].list); sys->sig[sig].active = 1; sys->sig_active = 1; @@ -221,6 +216,7 @@ #ifdef SA_NODEFER /* BSD/OS doesn't have this, for one. */ act.sa_flags &= ~SA_NODEFER; #endif + act.sa_flags |= sys->sa_flags; sigaction(sig,&act,NULL); } } @@ -266,6 +262,7 @@ source->num_events = 0; source->time_queue = source->time_run = NULL; + source->sa_flags = 0; source->do_jmp = 0; source->sig_active = 0; for (i = 0; i < OOP_NUM_SIGNALS; ++i) { @@ -280,6 +277,10 @@ return source; } +void oop_sys_set_sa_flags(oop_source_sys *s, int flags) { + s->sa_flags = flags; +} + static void *sys_time_run(oop_source_sys *sys) { void *ret = OOP_CONTINUE; while (OOP_CONTINUE == ret && NULL != sys->time_run) { @@ -379,6 +380,8 @@ sys->sig[i].ptr = h->next; ret = h->f(&sys->oop,i,h->v); } + assert(tv.tv_usec >= 0); + assert(tv.tv_usec < 1000000); } if (OOP_CONTINUE != ret) { sys->sig_active = 1; /* come back */