X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet_socket.c;h=d8bb007876320dbe72536a78748e15cac0b87a7d;hp=a45bc204fad49a162d08d8a263b80b14afd5a6e0;hb=708314df2f61675d0f54e541c9fff62ac1f433b5;hpb=178e52f76ef4ba40748c13ea7e518837394d6dbc diff --git a/src/net_socket.c b/src/net_socket.c index a45bc204..d8bb0078 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -1,7 +1,7 @@ /* net_socket.c -- Handle various kinds of sockets. Copyright (C) 1998-2005 Ivo Timmermans, - 2000-2010 Guus Sliepen + 2000-2012 Guus Sliepen 2006 Scott Lamb 2009 Florian Forster @@ -180,6 +180,10 @@ int setup_listen_socket(const sockaddr_t *sa) { return -1; } +#ifdef FD_CLOEXEC + fcntl(nfd, F_SETFD, FD_CLOEXEC); +#endif + /* Optimize TCP settings */ option = 1; @@ -238,6 +242,10 @@ int setup_vpn_in_socket(const sockaddr_t *sa) { return -1; } +#ifdef FD_CLOEXEC + fcntl(nfd, F_SETFD, FD_CLOEXEC); +#endif + #ifdef O_NONBLOCK { int flags = fcntl(nfd, F_GETFL); @@ -410,6 +418,10 @@ begin: c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP); +#ifdef FD_CLOEXEC + fcntl(c->socket, F_SETFD, FD_CLOEXEC); +#endif + if(c->socket == -1) { ifdebug(CONNECTIONS) logger(LOG_ERR, "Creating socket for %s failed: %s", c->hostname, sockstrerror(sockerrno)); goto begin;