diff --git a/configure.in b/configure.in
index 5790a39712f067a000cf8c665dc134304469621e..60293b226f0fe731aaf4f21d27559745a18982ec 100644
--- a/configure.in
+++ b/configure.in
@@ -24,7 +24,7 @@ case "$host" in
     ;;
 esac
 
-AC_CHECK_HEADERS(poll.h sys/select.h)
+AC_CHECK_HEADERS(poll.h sys/select.h sys/socket.h)
 
 AC_CHECK_LIB(adns,adns_init,[
   ADNS_LIBS="-ladns"
diff --git a/signal.c b/signal.c
index 5620a20b24d14c04b4b77b1e8a5506a17e0fd45a..9f2343ebaf39a510611c6d5e0682c5d1a019362e 100644
--- a/signal.c
+++ b/signal.c
@@ -9,6 +9,7 @@
 #include <assert.h>
 #include <signal.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #define MAGIC 5131
 
@@ -21,7 +22,7 @@ struct sig_handler {
 struct sig_signal {
 	struct sig_handler *list,*ptr;
 	struct sigaction old;
-	int active;
+	volatile sig_atomic_t active;
 };
 
 struct oop_adapter_signal {
@@ -195,6 +196,11 @@ oop_adapter_signal *oop_signal_new(oop_source *source) {
 		return NULL;
 	}
 
+        fcntl(s->pipefd[0],F_SETFD,FD_CLOEXEC);
+        fcntl(s->pipefd[1],F_SETFD,FD_CLOEXEC);
+        fcntl(s->pipefd[0],F_SETFL,O_NONBLOCK);
+        fcntl(s->pipefd[1],F_SETFL,O_NONBLOCK);
+
 	s->oop.on_fd = sig_on_fd;
 	s->oop.cancel_fd = sig_cancel_fd;
 	s->oop.on_time = sig_on_time;
diff --git a/sys.c b/sys.c
index f33a63141eb29cd1345f86639fccb219313dcbb5..2f6bbb0986d36e02e7129728c45829218a5c2e5e 100644
--- a/sys.c
+++ b/sys.c
@@ -19,6 +19,10 @@
 #include <sys/select.h>
 #endif
 
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
 #define MAGIC 0x9643
 
 struct sys_time {
@@ -37,7 +41,7 @@ struct sys_signal_handler {
 struct sys_signal {
 	struct sys_signal_handler *list,*ptr;
 	struct sigaction old;
-	int active;
+	volatile sig_atomic_t active;
 };
 
 struct sys_file_handler {