laforge
/
openbts-osmo
Archived
1
0
Fork 0

Set FD_CLOEXEC flag on all sockets.

We don't want them to be inherited on exec(). We use exec() to run Transceiver and it OpenBTS process crashes, transceiver becomes owner of all LISTEN sockets.
master
Alexander Chemeris 12 years ago committed by Thomas Tsou
parent 08bdbb921c
commit f7d78ff578
  1. 17
      public-trunk/CommonLibs/Sockets.cpp

@ -234,6 +234,11 @@ void UDPSocket::open(unsigned short localPort)
perror("socket() failed");
throw SocketError();
}
// Set "close on exec" flag to avoid open sockets inheritance by
// child processes, like 'transceiver'.
int flags = fcntl(mSocketFD, F_GETFD);
if (flags >= 0) fcntl(mSocketFD, F_SETFD, flags | FD_CLOEXEC);
// bind
struct sockaddr_in address;
@ -280,6 +285,10 @@ void UDDSocket::open(const char* localPath)
perror("socket() failed");
throw SocketError();
}
// Set "close on exec" flag to avoid open sockets inheritance by
// child processes, like 'transceiver'.
int flags = fcntl(mSocketFD, F_GETFD);
if (flags >= 0) fcntl(mSocketFD, F_SETFD, flags | FD_CLOEXEC);
// bind
struct sockaddr_un address;
@ -313,6 +322,10 @@ ConnectionSocket::ConnectionSocket(int af, int type, int protocol)
// LOG(ERROR) << "socket() failed with errno=" << errsv;
mSocketFD = -1;
}
// Set "close on exec" flag to avoid open sockets inheritance by
// child processes, like 'transceiver'.
int flags = fcntl(mSocketFD, F_GETFD);
if (flags >= 0) fcntl(mSocketFD, F_SETFD, flags | FD_CLOEXEC);
}
ConnectionSocket::~ConnectionSocket()
@ -393,6 +406,10 @@ ConnectionServerSocket::ConnectionServerSocket(int af, int type, int protocol)
// LOG(ERROR) << "socket() failed with errno=" << errsv;
mSocketFD = -1;
}
// Set "close on exec" flag to avoid open sockets inheritance by
// child processes, like 'transceiver'.
int flags = fcntl(mSocketFD, F_GETFD);
if (flags >= 0) fcntl(mSocketFD, F_SETFD, flags | FD_CLOEXEC);
}
bool ConnectionServerSocket::bindInternal(const sockaddr *addr, int addrlen,