Skip to content
Snippets Groups Projects
Commit 8ac68b07 authored by Dan Egnor's avatar Dan Egnor
Browse files

Signal handling fixes.

parent 6ce5dd5e
Branches
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ struct sig_signal { ...@@ -27,7 +27,7 @@ struct sig_signal {
struct oop_adapter_signal { struct oop_adapter_signal {
oop_source oop; oop_source oop;
int magic,pipefd[2],pipeflag; int magic,pipefd[2];
oop_source *source; /* backing source */ oop_source *source; /* backing source */
struct sig_signal sig[OOP_NUM_SIGNALS]; struct sig_signal sig[OOP_NUM_SIGNALS];
int num_events; int num_events;
...@@ -41,26 +41,10 @@ static oop_adapter_signal *verify_source(oop_source *source) { ...@@ -41,26 +41,10 @@ static oop_adapter_signal *verify_source(oop_source *source) {
return s; return s;
} }
static sigset_t block(void) {
sigset_t block,old;
sigfillset(&block);
sigprocmask(SIG_BLOCK,&block,&old);
return old;
}
static void unblock(sigset_t old) {
sigprocmask(SIG_SETMASK,&old,NULL);
}
static void do_pipe(struct oop_adapter_signal *s) { static void do_pipe(struct oop_adapter_signal *s) {
const sigset_t old = block();
const char ch = '\0'; const char ch = '\0';
if (0 == s->pipeflag) {
s->pipeflag = 1;
write(s->pipefd[1],&ch,1); write(s->pipefd[1],&ch,1);
} }
unblock(old);
}
static void on_signal(int sig) { static void on_signal(int sig) {
oop_adapter_signal * const s = sig_owner[sig]; oop_adapter_signal * const s = sig_owner[sig];
...@@ -81,16 +65,11 @@ static void *on_pipe(oop_source *source,int fd,oop_event event,void *user) { ...@@ -81,16 +65,11 @@ static void *on_pipe(oop_source *source,int fd,oop_event event,void *user) {
oop_adapter_signal * const s = verify_source((oop_source *) user); oop_adapter_signal * const s = verify_source((oop_source *) user);
sigset_t save; sigset_t save;
int i; int i;
char ch; char buf[4096];
assert(fd == s->pipefd[0]); assert(fd == s->pipefd[0]);
assert(OOP_READ == event); assert(OOP_READ == event);
assert(1 == s->pipeflag); read(s->pipefd[0],buf,sizeof buf);
save = block();
read(s->pipefd[0],&ch,1);
s->pipeflag = 0;
unblock(save);
for (i = 0; i < OOP_NUM_SIGNALS; ++i) { for (i = 0; i < OOP_NUM_SIGNALS; ++i) {
if (s->sig[i].active) { if (s->sig[i].active) {
......
...@@ -357,15 +357,15 @@ void *oop_sys_run(oop_source_sys *sys) { ...@@ -357,15 +357,15 @@ void *oop_sys_run(oop_source_sys *sys) {
} }
if (0 < rv) { if (0 < rv) {
for (i = 0; i < sys->num_files && OOP_CONTINUE == ret; ++i) for (i = 0; OOP_CONTINUE == ret && i < sys->num_files; ++i)
if (FD_ISSET(i,&xfd) && NULL != sys->files[i][OOP_EXCEPTION].f) if (FD_ISSET(i,&xfd) && NULL != sys->files[i][OOP_EXCEPTION].f)
ret = sys->files[i][OOP_EXCEPTION].f(&sys->oop,i,OOP_EXCEPTION, ret = sys->files[i][OOP_EXCEPTION].f(&sys->oop,i,OOP_EXCEPTION,
sys->files[i][OOP_EXCEPTION].v); sys->files[i][OOP_EXCEPTION].v);
for (i = 0; i < sys->num_files && OOP_CONTINUE == ret; ++i) for (i = 0; OOP_CONTINUE == ret && i < sys->num_files; ++i)
if (FD_ISSET(i,&wfd) && NULL != sys->files[i][OOP_WRITE].f) if (FD_ISSET(i,&wfd) && NULL != sys->files[i][OOP_WRITE].f)
ret = sys->files[i][OOP_WRITE].f(&sys->oop,i,OOP_WRITE, ret = sys->files[i][OOP_WRITE].f(&sys->oop,i,OOP_WRITE,
sys->files[i][OOP_WRITE].v); sys->files[i][OOP_WRITE].v);
for (i = 0; i < sys->num_files && OOP_CONTINUE == ret; ++i) for (i = 0; OOP_CONTINUE == ret && i < sys->num_files; ++i)
if (FD_ISSET(i,&rfd) && NULL != sys->files[i][OOP_READ].f) if (FD_ISSET(i,&rfd) && NULL != sys->files[i][OOP_READ].f)
ret = sys->files[i][OOP_READ].f(&sys->oop,i,OOP_READ, ret = sys->files[i][OOP_READ].f(&sys->oop,i,OOP_READ,
sys->files[i][OOP_READ].v); sys->files[i][OOP_READ].v);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment