[rpc-port] Fix port creation 46/261546/4
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 21 Jul 2021 04:24:47 +0000 (13:24 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Wed, 21 Jul 2021 06:17:02 +0000 (06:17 +0000)
While getting the port creation request, AMD removes the existed port
first. And, AMD finds the port info. If the port exists, AMD sends the
result with a negative error value.

Change-Id: If7cc9e4d29181efd4036c51eb4b26a4db7e57106
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/modules/rpc-port/amd_rpc_port.cc
src/modules/rpc-port/port_manager.cc

index 5f31affbf81b9af6a77431b4f25514b9bc537c96..0ce9e40c1caacc37c95adfe52066407490133c3b 100644 (file)
@@ -18,6 +18,7 @@
 #include <amd_mod_common.h>
 #include <aul.h>
 #include <aul_cmd.h>
+#include <aul_proc.h>
 #include <aul_rpc_port.h>
 #include <aul_sock.h>
 #include <aul_svc.h>
@@ -346,6 +347,22 @@ static int DispatchRpcPortCreate(amd_request_h req) {
 
   uid_t target_uid = amd_request_get_target_uid(req);
   auto& inst = PortManager::GetInst();
+  inst.RemovePort(port_name, pid);
+  auto* port = inst.FindPort(app_id, port_name, target_uid);
+  if (port != nullptr) {
+    char buf[PATH_MAX] = { 0, };
+    int ret = aul_proc_get_cmdline(port->GetPid(), buf, sizeof(buf));
+    if (ret == AUL_R_OK) {
+      _E("Already exists. app_id(%s), port_name(%s), pid(%d)",
+          app_id, port_name, port->GetPid());
+      amd_request_send_result(req, -1);
+      return -1;
+    }
+
+    _E("Process(%d) is not running", port->GetPid());
+    inst.RemovePort(port_name, port->GetPid());
+  }
+
   int ret = inst.AddPort(app_id, port_name, pid, target_uid);
   if (ret < 0) {
     _E("Failed to add port. pid(%d), port_name(%s)", pid, port_name);
index d6bfb130c8d9590ec3e184e3e4d8535235d1cc4c..521281a74e6f4f2be752c16351daa1cbd885875f 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <amd.h>
 #include <aul.h>
-#include <aul_proc.h>
 #include <aul_rpc_port.h>
 #include <bundle_cpp.h>
 
@@ -70,24 +69,11 @@ bool PortManager::ExistPort(const std::string& app_id,
   if (port == nullptr)
     return false;
 
-  char buf[PATH_MAX] = { 0, };
-  int ret = aul_proc_get_cmdline(port->GetPid(), buf, sizeof(buf));
-  if (ret != AUL_R_OK) {
-    RemovePort(port->GetPortName(), port->GetPid());
-    return false;
-  }
-
   return true;
 }
 
 int PortManager::AddPort(const std::string& app_id,
     const std::string& port_name, pid_t pid, uid_t uid) {
-  if (ExistPort(app_id, port_name, uid)) {
-    _E("Already exists. app_id(%s), port_name(%s), uid(%u)",
-        app_id.c_str(), port_name.c_str(), uid);
-    return -EALREADY;
-  }
-
   auto* port = PortInfo::Create(app_id, port_name, pid, uid);
   if (port == nullptr)
     return -1;