From 91c3e078d61dad4a5f1c5b47a255114a547c784b Mon Sep 17 00:00:00 2001 From: liqinglin <996260657@qq.com> Date: Wed, 9 Oct 2024 19:48:53 +0800 Subject: [PATCH] =?UTF-8?q?dlopen=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liqinglin <996260657@qq.com> --- .../src/config/dm_config_manager.cpp | 34 +++++++---------- .../service/src/device_manager_service.cpp | 38 +++---------------- .../src/discovery/discovery_manager.cpp | 10 +---- .../service/src/softbus/softbus_listener.cpp | 10 +---- 4 files changed, 23 insertions(+), 69 deletions(-) diff --git a/services/implementation/src/config/dm_config_manager.cpp b/services/implementation/src/config/dm_config_manager.cpp index 578cb7d44..4f680c68d 100644 --- a/services/implementation/src/config/dm_config_manager.cpp +++ b/services/implementation/src/config/dm_config_manager.cpp @@ -139,28 +139,24 @@ DmConfigManager::~DmConfigManager() { void *so_handle = nullptr; for (auto iter = soAdapterLoadInfo_.begin(); iter != soAdapterLoadInfo_.end(); iter++) { - char path[PATH_MAX + 1] = {0x00}; - std::string soPathName = (iter->second).soPath + (iter->second).soName; - if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX) || - (realpath(soPathName.c_str(), path) == nullptr)) { + std::string soPathName = (iter->second).soName; + if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX)) { LOGE("File %{public}s canonicalization failed.", soPathName.c_str()); continue; } - so_handle = dlopen(path, RTLD_NOW | RTLD_NOLOAD); + so_handle = dlopen(soPathName.c_str(), RTLD_NOW | RTLD_NOLOAD); if (so_handle != nullptr) { LOGI("DmConfigManager so_handle is not nullptr first."); dlclose(so_handle); } } for (auto iter = soAuthLoadInfo_.begin(); iter != soAuthLoadInfo_.end(); iter++) { - char path[PATH_MAX + 1] = {0x00}; - std::string soPathName = (iter->second).soPath + (iter->second).soName; - if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX) || - (realpath(soPathName.c_str(), path) == nullptr)) { + std::string soPathName = (iter->second).soName; + if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX)) { LOGE("File %{public}s canonicalization failed.", soPathName.c_str()); continue; } - so_handle = dlopen(path, RTLD_NOW | RTLD_NOLOAD); + so_handle = dlopen(soPathName.c_str(), RTLD_NOW | RTLD_NOLOAD); if (so_handle != nullptr) { LOGI("DmConfigManager so_handle is not nullptr second."); dlclose(so_handle); @@ -189,16 +185,14 @@ std::shared_ptr DmConfigManager::GetCryptoAdapter(const std::str } void *so_handle = nullptr; - char path[PATH_MAX + 1] = {0x00}; - std::string soPathName = (soInfoIter->second).soPath + (soInfoIter->second).soName; - if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX) || - (realpath(soPathName.c_str(), path) == nullptr)) { + std::string soPathName = (soInfoIter->second).soName; + if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX)) { LOGE("File %{public}s canonicalization failed.", soPathName.c_str()); return nullptr; } - so_handle = dlopen(path, RTLD_NOW | RTLD_NODELETE); + so_handle = dlopen(soPathName.c_str(), RTLD_NOW | RTLD_NODELETE); if (so_handle == nullptr) { - LOGE("load crypto so %{public}s failed", soName.c_str()); + LOGE("load crypto so failed."); return nullptr; } @@ -224,14 +218,12 @@ void DmConfigManager::GetAuthAdapter(std::mapsecond).soPath + (iter->second).soName; - if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX) || - (realpath(soPathName.c_str(), path) == nullptr)) { + std::string soPathName = (iter->second).soName; + if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX)) { LOGE("File %{public}s canonicalization failed.", soPathName.c_str()); continue; } - so_handle = dlopen(path, RTLD_NOW | RTLD_NODELETE); + so_handle = dlopen(soPathName.c_str(), RTLD_NOW | RTLD_NODELETE); if (so_handle == nullptr) { LOGE("load auth so %{public}s failed", (iter->second).soName.c_str()); continue; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 42c66ffd8..eaaa52e02 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -885,15 +885,9 @@ bool DeviceManagerService::IsDMServiceImplReady() if (isImplsoLoaded_ && (dmServiceImpl_ != nullptr)) { return true; } - char path[PATH_MAX + 1] = {0x00}; - std::string soName = std::string(DM_LIB_LOAD_PATH) + std::string(LIB_IMPL_NAME); - if ((soName.length() == 0) || (soName.length() > PATH_MAX) || (realpath(soName.c_str(), path) == nullptr)) { - LOGE("File %{public}s canonicalization failed.", soName.c_str()); - return false; - } - void *so_handle = dlopen(path, RTLD_NOW | RTLD_NODELETE); + void *so_handle = dlopen(LIB_IMPL_NAME, RTLD_NOW | RTLD_NODELETE); if (so_handle == nullptr) { - LOGE("load libdevicemanagerserviceimpl so %{public}s failed, errMsg: %{public}s.", soName.c_str(), dlerror()); + LOGE("load libdevicemanagerserviceimpl so failed, errMsg: %{public}s.", dlerror()); return false; } dlerror(); @@ -1119,14 +1113,7 @@ void DeviceManagerService::UnloadDMServiceImplSo() if (dmServiceImpl_ != nullptr) { dmServiceImpl_->Release(); } - char path[PATH_MAX + 1] = {0x00}; - std::string soPathName = std::string(DM_LIB_LOAD_PATH) + std::string(LIB_IMPL_NAME); - if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX) || - (realpath(soPathName.c_str(), path) == nullptr)) { - LOGE("File %{public}s canonicalization failed.", soPathName.c_str()); - return; - } - void *so_handle = dlopen(path, RTLD_NOW | RTLD_NOLOAD); + void *so_handle = dlopen(LIB_IMPL_NAME, RTLD_NOW | RTLD_NOLOAD); if (so_handle != nullptr) { LOGI("DeviceManagerService so_handle is not nullptr."); dlclose(so_handle); @@ -1141,15 +1128,9 @@ bool DeviceManagerService::IsDMServiceAdapterLoad() return true; } - char path[PATH_MAX + 1] = {0x00}; - std::string soName = std::string(DM_LIB_LOAD_PATH) + std::string(LIB_DM_ADAPTER_NAME); - if ((soName.length() == 0) || (soName.length() > PATH_MAX) || (realpath(soName.c_str(), path) == nullptr)) { - LOGE("File %{public}s canonicalization failed.", soName.c_str()); - return false; - } - void *so_handle = dlopen(path, RTLD_NOW | RTLD_NODELETE); + void *so_handle = dlopen(LIB_DM_ADAPTER_NAME, RTLD_NOW | RTLD_NODELETE); if (so_handle == nullptr) { - LOGE("load dm service adapter so %{public}s failed.", soName.c_str()); + LOGE("load dm service adapter so failed."); return false; } dlerror(); @@ -1182,14 +1163,7 @@ void DeviceManagerService::UnloadDMServiceAdapter() } dmServiceImplExt_ = nullptr; - char path[PATH_MAX + 1] = {0x00}; - std::string soPathName = std::string(DM_LIB_LOAD_PATH) + std::string(LIB_DM_ADAPTER_NAME); - if ((soPathName.length() == 0) || (soPathName.length() > PATH_MAX) || - (realpath(soPathName.c_str(), path) == nullptr)) { - LOGE("File %{public}s canonicalization failed.", soPathName.c_str()); - return; - } - void *so_handle = dlopen(path, RTLD_NOW | RTLD_NOLOAD); + void *so_handle = dlopen(LIB_DM_ADAPTER_NAME, RTLD_NOW | RTLD_NOLOAD); if (so_handle != nullptr) { LOGI("dm service adapter so_handle is not nullptr."); dlclose(so_handle); diff --git a/services/service/src/discovery/discovery_manager.cpp b/services/service/src/discovery/discovery_manager.cpp index c283cccaf..1d7094d39 100644 --- a/services/service/src/discovery/discovery_manager.cpp +++ b/services/service/src/discovery/discovery_manager.cpp @@ -532,15 +532,9 @@ bool DiscoveryManager::IsCommonDependencyReady() if (isSoLoaded_ && dpConnector_ != nullptr && dpConnectorHandle_ != nullptr) { return true; } - char path[PATH_MAX + 1] = {0x00}; - std::string soName = std::string(DM_LIB_LOAD_PATH) + std::string(LIB_DM_COMDENPENDENCY_NAME); - if ((soName.length() == 0) || (soName.length() > PATH_MAX) || (realpath(soName.c_str(), path) == nullptr)) { - LOGE("File %{public}s canonicalization failed.", soName.c_str()); - return false; - } - dpConnectorHandle_ = dlopen(path, RTLD_NOW | RTLD_NODELETE); + dpConnectorHandle_ = dlopen(LIB_DM_COMDENPENDENCY_NAME, RTLD_NOW | RTLD_NODELETE); if (dpConnectorHandle_ == nullptr) { - LOGE("load libdevicemanagerdependency so %{public}s failed, errMsg: %{public}s.", soName.c_str(), dlerror()); + LOGE("load libdevicemanagerdependency so failed, errMsg: %{public}s.", dlerror()); return false; } dlerror(); diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 7d9f47ae0..377484589 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -817,15 +817,9 @@ bool SoftbusListener::IsDmRadarHelperReady() LOGI("IsDmRadarHelperReady alReady."); return true; } - char path[PATH_MAX + 1] = {0x00}; - std::string soName = std::string(DM_LIB_LOAD_PATH) + std::string(LIB_RADAR_NAME); - if ((soName.length() == 0) || (soName.length() > PATH_MAX) || (realpath(soName.c_str(), path) == nullptr)) { - LOGE("File %{public}s canonicalization failed.", soName.c_str()); - return false; - } - radarHandle_ = dlopen(path, RTLD_NOW); + radarHandle_ = dlopen(LIB_RADAR_NAME, RTLD_NOW); if (radarHandle_ == nullptr) { - LOGE("load libdevicemanagerradar so %{public}s failed.", soName.c_str()); + LOGE("load libdevicemanagerradar so failed."); return false; } dlerror(); -- Gitee