Pārlūkot izejas kodu

FD_CLOEXEC for konfd socket

Serj Kalichev 10 gadi atpakaļ
vecāks
revīzija
df7071db52
1 mainītis faili ar 5 papildinājumiem un 0 dzēšanām
  1. 5 0
      konf/net/net.c

+ 5 - 0
konf/net/net.c

@@ -8,6 +8,7 @@
 #include <sys/socket.h>
 #include <string.h>
 #include <sys/un.h>
+#include <fcntl.h>
 
 #include "konf/buf.h"
 #include "konf/query.h"
@@ -65,6 +66,10 @@ int konf_client_connect(konf_client_t *this)
 	if ((this->sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
 		return this->sock;
 
+#ifdef FD_CLOEXEC
+	fcntl(this->sock, F_SETFD, fcntl(this->sock, F_GETFD) | FD_CLOEXEC);
+#endif
+
 	raddr.sun_family = AF_UNIX;
 	strncpy(raddr.sun_path, this->path, USOCK_PATH_MAX);
 	raddr.sun_path[USOCK_PATH_MAX - 1] = '\0';