From 7bf76876ccaba4a4daadb369b5cdc29293545cba Mon Sep 17 00:00:00 2001 From: zhangyaomaggie Date: Mon, 2 Sep 2024 16:43:41 +0800 Subject: [PATCH] avoid data race for userId Signed-off-by: zhangyaomaggie --- services/backup_sa/src/module_ipc/service.cpp | 8 +++----- services/backup_sa/src/module_ipc/service_incremental.cpp | 5 ++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 2d9dc3fe3..edbe73329 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -168,9 +168,8 @@ UniqueFd Service::GetLocalCapabilities() return UniqueFd(-EPERM); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); - session_->SetSessionUserId(GetUserIdDefault()); VerifyCaller(); - string path = BConstants::GetSaBundleBackupRootDir(session_->GetSessionUserId()); + string path = BConstants::GetSaBundleBackupRootDir(GetUserIdDefault()); BExcepUltils::VerifyPath(path, false); UniqueFd fd(open(path.data(), O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR)); if (fd < 0) { @@ -184,7 +183,7 @@ UniqueFd Service::GetLocalCapabilities() cache.SetSystemFullName(GetOSFullName()); cache.SetDeviceType(GetDeviceType()); - auto bundleInfos = BundleMgrAdapter::GetFullBundleInfos(session_->GetSessionUserId()); + auto bundleInfos = BundleMgrAdapter::GetFullBundleInfos(GetUserIdDefault()); cache.SetBundleInfos(bundleInfos); cachedEntity.Persist(); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); @@ -1599,7 +1598,6 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res HILOGE("Get BackupInfo error, session is empty."); return BError(BError::Codes::SA_INVAL_ARG); } - session_->SetSessionUserId(GetUserIdDefault()); auto backupConnection = session_->CreateBackupConnection(bundleName); if (backupConnection == nullptr) { HILOGE("backupConnection is null. bundleName: %{public}s", bundleName.c_str()); @@ -1610,7 +1608,7 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res backupConnection->SetCallback(callConnected); backupConnection->SetCallDied(callDied); AAFwk::Want want = CreateConnectWant(bundleName); - auto ret = backupConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); + auto ret = backupConnection->ConnectBackupExtAbility(want, GetUserIdDefault()); if (ret) { HILOGE("ConnectBackupExtAbility faild, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); return BError(BError::Codes::SA_BOOT_EXT_FAIL); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index a5e09c357..400a76ac1 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -98,9 +98,8 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorIncreaseSessionCnt(__PRETTY_FUNCTION__); - session_->SetSessionUserId(GetUserIdDefault()); VerifyCaller(); - string path = BConstants::GetSaBundleBackupRootDir(session_->GetSessionUserId()); + string path = BConstants::GetSaBundleBackupRootDir(GetUserIdDefault()); BExcepUltils::VerifyPath(path, false); UniqueFd fd(open(path.data(), O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR)); if (fd < 0) { @@ -113,7 +112,7 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorGetSessionUserId(), bundleNames); + auto bundleInfos = BundleMgrAdapter::GetBundleInfosForIncremental(GetUserIdDefault(), bundleNames); cache.SetBundleInfos(bundleInfos, true); cachedEntity.Persist(); HILOGI("Service GetLocalCapabilitiesIncremental persist"); -- Gitee