Set close on exec
[platform/core/appfw/rpc-port.git] / src / server-socket-internal.cc
index d117faa..46baa25 100644 (file)
@@ -29,6 +29,7 @@ namespace rpc_port {
 namespace internal {
 
 ServerSocket::ServerSocket(int fd) : fd_(fd) {
+  SetCloseOnExec();
 }
 
 ServerSocket::~ServerSocket() {
@@ -67,6 +68,12 @@ int ServerSocket::Listen(int backlog) {
 
   return 0;
 }
+
+void ServerSocket::SetCloseOnExec() {
+  int flags = fcntl(fd_, F_GETFL, 0);
+  fcntl(fd_, F_SETFL, flags | O_CLOEXEC);
+  _I("Close on exec");
+}
 // LCOV_EXCL_STOP
 
 void ServerSocket::Close() {