From 16b8f19db36886619fedd470ece29a94b87e4d8c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 29 Nov 2012 18:55:08 +0100 Subject: [PATCH] use more portable fcntl method for FD_CLOEXEC bit, enable it on forgotten sockets --- src/main.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.cc b/src/main.cc index d05245b0..0eb1df2e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -30,6 +30,8 @@ #include #include #include +#include +#include using namespace Kakoune; using namespace std::placeholders; @@ -514,7 +516,8 @@ struct Server : public Singleton { m_filename = "/tmp/kak-" + int_to_str(getpid()); - m_listen_sock = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + m_listen_sock = socket(AF_UNIX, SOCK_STREAM, 0); + fcntl(m_listen_sock, F_SETFD, FD_CLOEXEC); sockaddr_un addr; addr.sun_family = AF_UNIX; strncpy(addr.sun_path, m_filename.c_str(), sizeof(addr.sun_path) - 1); @@ -531,6 +534,7 @@ struct Server : public Singleton int sock = accept(socket, (sockaddr*) &client_addr, &client_addr_len); if (sock == -1) throw runtime_error("accept failed"); + fcntl(sock, F_SETFD, FD_CLOEXEC); auto& buffer = *BufferManager::instance().begin(); RemoteUI* ui = new RemoteUI{sock}; @@ -619,7 +623,8 @@ RemoteClient* connect_to(const String& pid) { auto filename = "/tmp/kak-" + pid; - int sock = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + int sock = socket(AF_UNIX, SOCK_STREAM, 0); + fcntl(sock, F_SETFD, FD_CLOEXEC); sockaddr_un addr; addr.sun_family = AF_UNIX; strncpy(addr.sun_path, filename.c_str(), sizeof(addr.sun_path) - 1);