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:
parent
08bdbb921c
commit
f7d78ff578
|
@ -234,6 +234,11 @@ void UDPSocket::open(unsigned short localPort)
|
||||||
perror("socket() failed");
|
perror("socket() failed");
|
||||||
throw SocketError();
|
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
|
// bind
|
||||||
struct sockaddr_in address;
|
struct sockaddr_in address;
|
||||||
|
@ -280,6 +285,10 @@ void UDDSocket::open(const char* localPath)
|
||||||
perror("socket() failed");
|
perror("socket() failed");
|
||||||
throw SocketError();
|
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
|
// bind
|
||||||
struct sockaddr_un address;
|
struct sockaddr_un address;
|
||||||
|
@ -313,6 +322,10 @@ ConnectionSocket::ConnectionSocket(int af, int type, int protocol)
|
||||||
// LOG(ERROR) << "socket() failed with errno=" << errsv;
|
// LOG(ERROR) << "socket() failed with errno=" << errsv;
|
||||||
mSocketFD = -1;
|
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()
|
ConnectionSocket::~ConnectionSocket()
|
||||||
|
@ -393,6 +406,10 @@ ConnectionServerSocket::ConnectionServerSocket(int af, int type, int protocol)
|
||||||
// LOG(ERROR) << "socket() failed with errno=" << errsv;
|
// LOG(ERROR) << "socket() failed with errno=" << errsv;
|
||||||
mSocketFD = -1;
|
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,
|
bool ConnectionServerSocket::bindInternal(const sockaddr *addr, int addrlen,
|
||||||
|
|
Reference in New Issue