From 4f1237509ac776e7e292e8bc807073afbba08a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=81=E6=B4=8B?= Date: Wed, 10 Sep 2025 19:40:25 +0800 Subject: [PATCH] fix:RPC multi-threaded client and server permission management. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 袁洋 Change-Id: I85ff72746ee0c1415408a8858dabcc0a7d337ba9 --- .../dbinder/include/dbinder_softbus_client.h | 2 ++ .../dbinder/source/dbinder_softbus_client.cpp | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ipc/native/src/core/dbinder/include/dbinder_softbus_client.h b/ipc/native/src/core/dbinder/include/dbinder_softbus_client.h index f6335112..4d69e3ff 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_softbus_client.h +++ b/ipc/native/src/core/dbinder/include/dbinder_softbus_client.h @@ -75,7 +75,9 @@ private: ShutdownFunc shutdownFunc_ = nullptr; std::mutex loadSoMutex_; + std::mutex permissionMutex_; std::atomic exitFlag_ = false; + std::atomic sessionRefCount_ = 0; bool isLoaded_ = false; void *soHandle_ = nullptr; }; diff --git a/ipc/native/src/core/dbinder/source/dbinder_softbus_client.cpp b/ipc/native/src/core/dbinder/source/dbinder_softbus_client.cpp index 1911756e..66b29f17 100644 --- a/ipc/native/src/core/dbinder/source/dbinder_softbus_client.cpp +++ b/ipc/native/src/core/dbinder/source/dbinder_softbus_client.cpp @@ -16,7 +16,7 @@ #include "dbinder_softbus_client.h" #include - +#include "ipc_types.h" #include "check_instance_exit.h" #include "ipc_debug.h" #include "log_tags.h" @@ -68,8 +68,11 @@ bool DBinderSoftbusClient::OpenSoftbusClientSo() int32_t DBinderSoftbusClient::DBinderGrantPermission(int32_t uid, int32_t pid, const std::string &socketName) { + std::lock_guard lockGuard(permissionMutex_); CHECK_INSTANCE_EXIT_WITH_RETVAL(exitFlag_, SOFTBUS_CLIENT_INSTANCE_EXIT); if (grantPermissionFunc_ != nullptr) { + sessionRefCount_++; + ZLOGI(LOG_LABEL, "refCount + 1 socketName:%{public}s", socketName.c_str()); return grantPermissionFunc_(uid, pid, socketName.c_str()); } @@ -82,14 +85,21 @@ int32_t DBinderSoftbusClient::DBinderGrantPermission(int32_t uid, int32_t pid, c ZLOGE(LOG_LABEL, "dlsym DBinderGrantPermission fail, err msg:%{public}s", dlerror()); return SOFTBUS_CLIENT_DLSYM_FAILED; } - + sessionRefCount_++; + ZLOGI(LOG_LABEL, "refCount + 1 socketName:%{public}s", socketName.c_str()); return grantPermissionFunc_(uid, pid, socketName.c_str()); } int32_t DBinderSoftbusClient::DBinderRemovePermission(const std::string &socketName) { + std::lock_guard lockGuard(permissionMutex_); CHECK_INSTANCE_EXIT_WITH_RETVAL(exitFlag_, SOFTBUS_CLIENT_INSTANCE_EXIT); if (removePermissionFunc_ != nullptr) { + if (sessionRefCount_ != 0) { + ZLOGI(LOG_LABEL, "refCount not 0 socketName:%{public}s", socketName.c_str()); + sessionRefCount_--; + return ERR_NONE; + } return removePermissionFunc_(socketName.c_str()); } @@ -102,7 +112,11 @@ int32_t DBinderSoftbusClient::DBinderRemovePermission(const std::string &socketN ZLOGE(LOG_LABEL, "dlsym DBinderRemovePermission fail, err msg:%{public}s", dlerror()); return SOFTBUS_CLIENT_DLSYM_FAILED; } - + if (sessionRefCount_ != 0) { + ZLOGI(LOG_LABEL, "refCount not 0 socketName:%{public}s", socketName.c_str()); + sessionRefCount_--; + return ERR_NONE; + } return removePermissionFunc_(socketName.c_str()); } -- Gitee