From: Hwankyu Jhun Date: Fri, 5 Apr 2024 00:03:07 +0000 (+0900) Subject: Delete port path X-Git-Tag: accepted/tizen/unified/20240405.115720~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00a4a0e3048b306607f877ef9dda77faa7b3d5c5;p=platform%2Fcore%2Fappfw%2Frpc-port.git Delete port path While calling a destructor of Stub, the port path should be deleted if the caller is a daemon or service. Change-Id: I806d5f0aeafbcf8740dbd2d4ef52b0fa5408d4b1 Signed-off-by: Hwankyu Jhun --- diff --git a/src/stub-internal.cc b/src/stub-internal.cc index df135a1..400e2d3 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -108,6 +108,11 @@ Stub::~Stub() { listener_ = nullptr; server_.reset(); + if (port_path_.empty()) { + _W("Delete port path=%s", port_path_.c_str()); + unlink(port_path_.c_str()); + } + freed_stubs_.insert(this); } @@ -188,11 +193,11 @@ int Stub::CreatePort() { if (getenv("AUL_APPID") == nullptr) { std::string name = Aul::GetName(getpid()); if (!name.empty()) { - std::string endpoint = Aul::GetPortPath(name, GetPortName(), getuid()); - int fd = GetFdFromSystemd(endpoint); + port_path_ = Aul::GetPortPath(name, GetPortName(), getuid()); + int fd = GetFdFromSystemd(); if (fd > -1) return fd; - fd = CreateServerSocket(endpoint); + fd = CreateServerSocket(); if (fd > -1) return fd; } } @@ -209,10 +214,10 @@ int Stub::CreatePort() { return fd; } -int Stub::GetFdFromSystemd(const std::string& endpoint) { +int Stub::GetFdFromSystemd() { int fds = sd_listen_fds(0); for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + fds; ++fd) { - if (sd_is_socket_unix(fd, SOCK_STREAM, 1, endpoint.c_str(), 0) > 0) + if (sd_is_socket_unix(fd, SOCK_STREAM, 1, port_path_.c_str(), 0) > 0) return fd; } @@ -220,10 +225,10 @@ int Stub::GetFdFromSystemd(const std::string& endpoint) { return -1; } -int Stub::CreateServerSocket(const std::string& endpoint) { +int Stub::CreateServerSocket() { try { ServerSocket socket; - socket.Bind(endpoint); + socket.Bind(port_path_); socket.Listen(128); return socket.RemoveFd(); } catch (const Exception& e) { diff --git a/src/stub-internal.hh b/src/stub-internal.hh index 71aaefc..b1ac248 100644 --- a/src/stub-internal.hh +++ b/src/stub-internal.hh @@ -107,13 +107,14 @@ class Stub { const std::string& instance, const std::string& port_type, int fd); void RemoveAcceptedPorts(std::string instance); std::recursive_mutex& GetMutex() const; - int GetFdFromSystemd(const std::string& endpoint); - int CreateServerSocket(const std::string& endpoint); + int GetFdFromSystemd(); + int CreateServerSocket(); private: std::shared_ptr access_controller_ = std::make_shared(); std::string port_name_; + std::string port_path_; std::list> ports_; IEventListener* listener_ = nullptr; std::unique_ptr server_;