From 8ac68b07e45dbf7e12e9ac36d7826e164262984e Mon Sep 17 00:00:00 2001
From: Dan Egnor <egnor@ofb.net>
Date: Fri, 22 Mar 2002 03:28:56 +0000
Subject: [PATCH] Signal handling fixes.

---
 signal.c | 29 ++++-------------------------
 sys.c    |  6 +++---
 2 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/signal.c b/signal.c
index 9f2343e..7ab5667 100644
--- a/signal.c
+++ b/signal.c
@@ -27,7 +27,7 @@ struct sig_signal {
 
 struct oop_adapter_signal {
 	oop_source oop;
-	int magic,pipefd[2],pipeflag;
+	int magic,pipefd[2];
 	oop_source *source; /* backing source */
 	struct sig_signal sig[OOP_NUM_SIGNALS];
 	int num_events;
@@ -41,25 +41,9 @@ static oop_adapter_signal *verify_source(oop_source *source) {
 	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) {
-	const sigset_t old = block();
 	const char ch = '\0';
-	if (0 == s->pipeflag) {
-		s->pipeflag = 1;
-		write(s->pipefd[1],&ch,1);
-	}
-	unblock(old);
+	write(s->pipefd[1],&ch,1);
 }
 
 static void on_signal(int sig) {
@@ -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);
 	sigset_t save;
 	int i;
-	char ch;
+	char buf[4096];
 
 	assert(fd == s->pipefd[0]);
 	assert(OOP_READ == event);
-	assert(1 == s->pipeflag);
-
-	save = block();
-	read(s->pipefd[0],&ch,1);
-	s->pipeflag = 0;
-	unblock(save);
+	read(s->pipefd[0],buf,sizeof buf);
 
 	for (i = 0; i < OOP_NUM_SIGNALS; ++i) {
 		if (s->sig[i].active) {
diff --git a/sys.c b/sys.c
index 2f6bbb0..60d496d 100644
--- a/sys.c
+++ b/sys.c
@@ -357,15 +357,15 @@ void *oop_sys_run(oop_source_sys *sys) {
 		}
 
 		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)
 					ret = sys->files[i][OOP_EXCEPTION].f(&sys->oop,i,OOP_EXCEPTION,
 					                          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)
 					ret = sys->files[i][OOP_WRITE].f(&sys->oop,i,OOP_WRITE,
 					                           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)
 					ret = sys->files[i][OOP_READ].f(&sys->oop,i,OOP_READ,
 					                          sys->files[i][OOP_READ].v);
-- 
GitLab