Commit Diff


commit - 16012c8fa7ede11487b07a31204fbe9a5238c632
commit + b5c4cc839e3178788f0203eb2cde9d0bf8fc0b76
blob - a13ac97dd52717b9f457db9b0d75dbc82be65dd9
blob + 9fef9a566dfecfdd2a78900599239189d6509306
--- kamid/control.c
+++ kamid/control.c
@@ -26,6 +26,7 @@
 #include <net/if.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -125,7 +126,7 @@ control_listen(int fd)
 void
 control_accept(int listenfd, short event, void *bula)
 {
-	int			 connfd;
+	int			 connfd, flags;
 	socklen_t		 len;
 	struct sockaddr_un	 sun;
 	struct ctl_conn		*c;
@@ -135,8 +136,7 @@ control_accept(int listenfd, short event, void *bula)
 		return;
 
 	len = sizeof(sun);
-	if ((connfd = accept4(listenfd, (struct sockaddr *)&sun, &len,
-	    SOCK_CLOEXEC | SOCK_NONBLOCK)) == -1) {
+	if ((connfd = accept(listenfd, (struct sockaddr *)&sun, &len)) == -1) {
 		/*
 		 * Pause accept if we are out of file descriptors, or
 		 * libevent will haunt us here too.
@@ -152,6 +152,19 @@ control_accept(int listenfd, short event, void *bula)
 		return;
 	}
 
+	if ((flags = fcntl(connfd, F_GETFL)) == -1) {
+		log_warn("%s: fcntl F_GETFL", __func__);
+		close(connfd);
+		return;
+	}
+	flags |= O_NONBLOCK;
+	if (fcntl(connfd, F_SETFL, flags) == -1 ||
+	    fcntl(connfd, F_SETFD, FD_CLOEXEC) == -1) {
+		log_warn("%s: can't set nonblock/cloexec", __func__);
+		close(connfd);
+		return;
+	}
+
 	if ((c = calloc(1, sizeof(struct ctl_conn))) == NULL) {
 		log_warn("%s: calloc", __func__);
 		close(connfd);