Modify implementation related to sync function 39/316039/6
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 12 Aug 2024 21:55:06 +0000 (06:55 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 13 Aug 2024 04:11:43 +0000 (13:11 +0900)
- Change retrying count to 250.
- Check whether the stub is system daemon or not
- Fix a bug about delegate invocation

Change-Id: I49b36eb990957dabaa29d462b74e6c32df501c93
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/rpc-port/aul-internal.cc
src/rpc-port/proxy-internal.cc
src/rpc-port/proxy-port-internal.cc
src/rpc-port/stub-internal.cc

index 628cd5f938d6568045001986aa90814ae429a2ac..ec32a6cae942d7585bd9823fe62f3c7f20b077b9 100644 (file)
@@ -17,6 +17,8 @@
 #include <aul.h>
 #include <aul_rpc_port.h>
 #include <aul_proc.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include <memory>
 
@@ -27,6 +29,8 @@
 namespace rpc_port {
 namespace internal {
 
+const uid_t kRegularUidMin = 5000;
+
 std::string Aul::GetName(int pid) {
   char* name = nullptr;
   if (aul_proc_get_name(pid, &name) != AUL_R_OK) return "";
@@ -36,16 +40,13 @@ std::string Aul::GetName(int pid) {
 }
 
 std::string Aul::GetAppId(int pid) {
-  char app_id[256] = { 0, };
-  int ret = aul_app_get_appid_bypid(pid, app_id, sizeof(app_id));
-  if (ret != AUL_R_OK) {
-    // LCOV_EXCL_START
-    _E("aul_app_get_appid_bypid() is failed. pid(%d), error(%d)", pid, ret);
-    return GetName(pid);
-    // LCOV_EXCL_STOP
+  if (getuid() >= kRegularUidMin) {
+    char app_id[256] = { 0, };
+    int ret = aul_app_get_appid_bypid(pid, app_id, sizeof(app_id));
+    if (ret == AUL_R_OK) return std::string(app_id);
   }
 
-  return std::string(app_id);
+  return GetName(pid);
 }
 
 std::string Aul::GetPortPath(const std::string& app_id,
index 4e9b202d0b09dfe9e598734887927ceb902a7929..3734b7c16370aa6ce8cf949619250a09564e0c61 100644 (file)
@@ -238,7 +238,7 @@ int Proxy::ConnectSync(std::string appid, std::string port_name,
 
 bool Proxy::WaitUntilPortCreation() {
   file_monitor_.reset(new FileMonitor(port_path_));
-  int retry_count = rpc_port_get_timeout() / 1000;
+  int retry_count = rpc_port_get_timeout() / 100;
   do {
     if (file_monitor_->Exist()) return true;
 
index 802693a09030541915bc6f47a521cc9270d4e96c..a93a0d8a993f53608fcfff1a60825780b8d00ad2 100644 (file)
@@ -30,7 +30,10 @@ ProxyPort::ProxyPort(int read_fd, int write_fd, std::string id,
                      IEvent* listener, bool is_delegate)
     : Port(read_fd, write_fd, std::move(id)),
       listener_(listener),
-      is_delegate_(is_delegate) {}
+      is_delegate_(is_delegate) {
+  if (read_fd > -1)
+    Watch(read_fd);
+}
 
 ProxyPort::~ProxyPort() { GLib::SourceDestroy(source_); }
 
index d0e89d4f1479c7ac96dd3574386dff16fd873717..68864aa79b9bee69c418077bef96be004b0cebb6 100644 (file)
@@ -150,8 +150,9 @@ void Stub::RemoveAcceptedPorts(std::string instance) {
 }
 
 int Stub::CreatePort() {
-  if (getenv("AUL_APPID") == nullptr) {
-    std::string name = Aul::GetName(getpid());
+  const char* appid = getenv("AUL_APPID");
+  if (getuid() < kRegularUidMin || appid == nullptr) {
+    std::string name = appid ? appid : Aul::GetName(getpid());
     if (!name.empty()) {
       port_path_ = Aul::GetPortPath(name, GetPortName(), getuid());
       int fd = GetFdFromSystemd();
@@ -301,7 +302,8 @@ std::recursive_mutex& Stub::GetMutex() const {
 void Stub::CheckPermission(const std::shared_ptr<Request>& request,
                            const std::shared_ptr<ClientSocket>& client,
                            const std::shared_ptr<PeerCred>& cred) {
-  std::string app_id = Aul::GetAppId(cred->GetPid());
+  std::string app_id;
+  if (cred->GetUid() >= kRegularUidMin) app_id = Aul::GetAppId(cred->GetPid());
   auto response_func = [=](int res) -> void {
     if (freed_stubs_.find(this) != freed_stubs_.end())
       return;  // LCOV_EXCL_LINE