1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-30 23:37:17 +03:00

use more portable fcntl method for FD_CLOEXEC bit, enable it on forgotten sockets

This commit is contained in:
Maxime Coste 2012-11-29 18:55:08 +01:00
parent 0955ef5eb0
commit 16b8f19db3

View File

@ -30,6 +30,8 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
using namespace Kakoune;
using namespace std::placeholders;
@ -514,7 +516,8 @@ struct Server : public Singleton<Server>
{
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<Server>
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);