Set close on exec 74/298574/1
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 11 Sep 2023 02:17:36 +0000 (11:17 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 11 Sep 2023 02:17:36 +0000 (11:17 +0900)
To avoid inheriting fd to the child process, this patch sets close on
exec flag to fd.

Change-Id: I3ab2255e8cd80ad50ffbf355e51f0acec1030d68
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/server-socket-internal.cc
src/server-socket-internal.hh

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() {
index 47ca970..43e392a 100644 (file)
@@ -32,6 +32,7 @@ class ServerSocket {
   int GetFd() const;
   int Listen(int backlog);
   void Close();
+  void SetCloseOnExec();
 
  private:
   int fd_;