Set close on exec for client socket 52/298652/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 12 Sep 2023 05:58:06 +0000 (14:58 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 12 Sep 2023 05:58:06 +0000 (14:58 +0900)
To close the client socket fd, this patch sets O_CLOEXEC flag using fcntl().

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

index 295d172..8ba4ffb 100644 (file)
@@ -41,6 +41,7 @@ ClientSocket::ClientSocket() {
 }
 
 ClientSocket::ClientSocket(int fd) : fd_(fd) {
+  SetCloseOnExec();
 }
 
 ClientSocket::~ClientSocket() {
@@ -48,6 +49,12 @@ ClientSocket::~ClientSocket() {
     Close();
 }
 
+void ClientSocket::SetCloseOnExec() {
+  int flags = fcntl(fd_, F_GETFL, 0);
+  fcntl(fd_, F_SETFL, flags | O_CLOEXEC);
+  _I("Close on exec. fd(%d)", fd_);
+}
+
 void ClientSocket::Close() {
   if (fd_ > -1) {
     close(fd_);
index 9b02047..d033b2e 100644 (file)
@@ -37,6 +37,7 @@ class ClientSocket {
   int GetFd() const;
   int RemoveFd();
   void SetNonblock();
+  void SetCloseOnExec();
 
  private:
   int fd_;
index 46baa25..a5b1640 100644 (file)
@@ -72,7 +72,7 @@ int ServerSocket::Listen(int backlog) {
 void ServerSocket::SetCloseOnExec() {
   int flags = fcntl(fd_, F_GETFL, 0);
   fcntl(fd_, F_SETFL, flags | O_CLOEXEC);
-  _I("Close on exec");
+  _I("Close on exec. fd(%d)", fd_);
 }
 // LCOV_EXCL_STOP