Browse Source

FD_CLOEXEC for konfd socket

Serj Kalichev 9 years ago
parent
commit
df7071db52
1 changed files with 5 additions and 0 deletions
  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';