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.
This commit is contained in:
Alexander Chemeris 2010-11-23 10:48:38 +03:00 committed by Thomas Tsou
parent 08bdbb921c
commit f7d78ff578
1 changed files with 17 additions and 0 deletions

View File

@ -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,