From 0fdfe287d7454e013ca52a6fc3bbf0ddc0496e65 Mon Sep 17 00:00:00 2001 From: Rayllll Date: Sat, 17 May 2025 22:36:10 +0800 Subject: [PATCH 1/3] Signed-off-by: Rayllll fix util & add clear space --- services/updater_main.h | 1 + services/updater_ui.cpp | 1 + utils/include/utils_common.h | 3 +++ utils/include/utils_fs.h | 3 --- utils/utils_common.cpp | 48 ++++++++++++++++++++++++++++++++++++ utils/utils_fs.cpp | 47 ----------------------------------- 6 files changed, 53 insertions(+), 50 deletions(-) diff --git a/services/updater_main.h b/services/updater_main.h index 3118d01d..2dcc7642 100644 --- a/services/updater_main.h +++ b/services/updater_main.h @@ -27,6 +27,7 @@ enum FactoryResetMode { USER_WIPE_DATA = 0, FACTORY_WIPE_DATA, MENU_WIPE_DATA, + CLEAR_SPACE, INVALID_MODE, }; diff --git a/services/updater_ui.cpp b/services/updater_ui.cpp index ce20ea0e..8dc258a3 100644 --- a/services/updater_ui.cpp +++ b/services/updater_ui.cpp @@ -118,6 +118,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) Utils::RemoveUpdateInfoFromMisc("sdcard_update"); GetFacade().ShowLogRes(res == UPDATE_CORRUPT ? TR(LOGRES_VERIFY_FAILED) : TR(LOGRES_UPDATE_FAILED)); GetFacade().ShowFailedPage(); + NotifyAutoReboot(upParams.updateMode); return; } GetFacade().ShowLogRes(TR(LABEL_UPD_OK_DONE)); diff --git a/utils/include/utils_common.h b/utils/include/utils_common.h index de27cc06..cf108560 100644 --- a/utils/include/utils_common.h +++ b/utils/include/utils_common.h @@ -27,6 +27,9 @@ namespace Utils { bool PathToRealPath(const std::string &path, std::string &realPath); void UsSleep(int usec); bool IsUpdaterMode(); +void* LoadLibrary(const std::string &libName, const std::string &libPath); +void CloseLibrary(void* handle); +void* GetFunction(void* handle, const std::string &funcName); } // Utils } // Updater #endif // UTILS_COMMON_H \ No newline at end of file diff --git a/utils/include/utils_fs.h b/utils/include/utils_fs.h index 3170aa6c..a257f81b 100644 --- a/utils/include/utils_fs.h +++ b/utils/include/utils_fs.h @@ -29,9 +29,6 @@ int64_t GetFilesFromDirectory(const std::string &path, std::vector bool RemoveDir(const std::string &path); bool IsFileExist(const std::string &path); bool IsDirExist(const std::string &path); -void* LoadLibrary(const std::string &libName, const std::string &libPath); -void CloseLibrary(void* handle); -void* GetFunction(void* handle, const std::string &funcName); } // Utils } // Updater #endif // UTILS_FS_H \ No newline at end of file diff --git a/utils/utils_common.cpp b/utils/utils_common.cpp index 31186a7a..6c1e7c35 100644 --- a/utils/utils_common.cpp +++ b/utils/utils_common.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -76,5 +77,52 @@ bool IsUpdaterMode() LOG(INFO) << "normal mode"; return false; } + +void* LoadLibrary(const std::string &libName, const std::string &libPath) +{ + if (libName.empty()) { + LOG(ERROR) << "lib name is empty"; + return nullptr; + } + if (libPath != "/system/lib64/" && libPath != "/vendor/lib64/") { + LOG(ERROR) << "lib path invalid"; + return nullptr; + } + std::string libAbsPath = libPath + libName; + char realPath[PATH_MAX + 1] = {0}; + if (realpath(libAbsPath.c_str(), realPath) == nullptr) { + LOG(ERROR) << "realpath error"; + return nullptr; + } + void* handle = dlopen(libAbsPath.c_str(), RTLD_LAZY); + if (handle == nullptr) { + LOG(ERROR) << "dlopen fail, lib name = " << libName << "; dlerror = " << dlerror(); + return nullptr; + } + return handle; +} + +void CloseLibrary(void* handle) +{ + if (handle == nullptr) { + LOG(ERROR) << "handle is nulptr"; + return; + } + dlclose(handle); + handle = nullptr; +} + +void* GetFunction(void* handle, const std::string &funcName) +{ + if (handle == nullptr) { + LOG(ERROR) << "handle is nullptr"; + return nullptr; + } + if (funcName.empty()) { + LOG(ERROR) << "func name is empty"; + return nullptr; + } + return dlsym(handle, funcName.c_str()); +} } // Utils } // updater diff --git a/utils/utils_fs.cpp b/utils/utils_fs.cpp index 28e15433..d14497f3 100644 --- a/utils/utils_fs.cpp +++ b/utils/utils_fs.cpp @@ -149,52 +149,5 @@ bool IsDirExist(const std::string &path) } return false; } - -void* LoadLibrary(const std::string &libName, const std::string &libPath) -{ - if (libName.empty()) { - LOG(ERROR) << "lib name is empty"; - return nullptr; - } - if (libPath != "/system/lib64/" && libPath != "/vendor/lib64/") { - LOG(ERROR) << "lib path invalid"; - return nullptr; - } - std::string libAbsPath = libPath + libName; - char realPath[PATH_MAX + 1] = {0}; - if (realpath(libAbsPath.c_str(), realPath) == nullptr) { - LOG(ERROR) << "realpath error"; - return nullptr; - } - void* handle = dlopen(libAbsPath.c_str(), RTLD_LAZY); - if (handle == nullptr) { - LOG(ERROR) << "dlopen fail, lib name = " << libName << "; dlerror = " << dlerror(); - return nullptr; - } - return handle; -} - -void CloseLibrary(void* handle) -{ - if (handle == nullptr) { - LOG(ERROR) << "handle is nulptr"; - return; - } - dlclose(handle); - handle = nullptr; -} - -void* GetFunction(void* handle, const std::string &funcName) -{ - if (handle == nullptr) { - LOG(ERROR) << "handle is nullptr"; - return nullptr; - } - if (funcName.empty()) { - LOG(ERROR) << "func name is empty"; - return nullptr; - } - return dlsym(handle, funcName.c_str()); -} } // Utils } // updater -- Gitee From 4a02140914bf17f90c34ce7c348030e29a8e5b14 Mon Sep 17 00:00:00 2001 From: Rayllll Date: Sat, 17 May 2025 22:36:10 +0800 Subject: [PATCH 2/3] Signed-off-by: Rayllll fix util & add clear space Signed-off-by: Rayllll --- services/updater.cpp | 13 ++++++---- services/updater_main.h | 1 + services/updater_ui.cpp | 1 + utils/include/utils_common.h | 3 +++ utils/include/utils_fs.h | 3 --- utils/utils_common.cpp | 48 ++++++++++++++++++++++++++++++++++++ utils/utils_fs.cpp | 47 ----------------------------------- 7 files changed, 61 insertions(+), 55 deletions(-) diff --git a/services/updater.cpp b/services/updater.cpp index 22b392ca..48da8d13 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -537,18 +537,21 @@ void ExcuteSubProc(const UpdaterParams &upParams, const std::string &fullPath, i } } const std::string retryPara = upParams.retryCount > 0 ? "retry=1" : "retry=0"; + int ret = 0; if (upParams.updateBin.size() > 0) { LOG(INFO) << "Binary Path:" << upParams.updateBin[upParams.pkgLocation].c_str(); - execl(fullPath.c_str(), fullPath.c_str(), upParams.updateBin[upParams.pkgLocation].c_str(), + ret = execl(fullPath.c_str(), fullPath.c_str(), upParams.updateBin[upParams.pkgLocation].c_str(), std::to_string(pipeWrite).c_str(), retryPara.c_str(), nullptr); } else if (upParams.updatePackage.size() > 0) { LOG(INFO) << "Binary Path:" << upParams.updatePackage[upParams.pkgLocation].c_str(); - execl(fullPath.c_str(), fullPath.c_str(), upParams.updatePackage[upParams.pkgLocation].c_str(), + ret = execl(fullPath.c_str(), fullPath.c_str(), upParams.updatePackage[upParams.pkgLocation].c_str(), std::to_string(pipeWrite).c_str(), retryPara.c_str(), nullptr); } - LOG(ERROR) << "Execute updater binary failed"; - UPDATER_LAST_WORD(UPDATE_ERROR, "Execute updater binary failed"); - exit(-1); + if (ret < 0) { + LOG(ERROR) << "Execute updater binary failed"; + UPDATER_LAST_WORD(UPDATE_ERROR, "Execute updater binary failed"); + exit(-1); + } } UpdaterStatus HandlePipeMsg(UpdaterParams &upParams, int pipeRead, bool &retryUpdate) diff --git a/services/updater_main.h b/services/updater_main.h index 3118d01d..2dcc7642 100644 --- a/services/updater_main.h +++ b/services/updater_main.h @@ -27,6 +27,7 @@ enum FactoryResetMode { USER_WIPE_DATA = 0, FACTORY_WIPE_DATA, MENU_WIPE_DATA, + CLEAR_SPACE, INVALID_MODE, }; diff --git a/services/updater_ui.cpp b/services/updater_ui.cpp index ce20ea0e..8dc258a3 100644 --- a/services/updater_ui.cpp +++ b/services/updater_ui.cpp @@ -118,6 +118,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) Utils::RemoveUpdateInfoFromMisc("sdcard_update"); GetFacade().ShowLogRes(res == UPDATE_CORRUPT ? TR(LOGRES_VERIFY_FAILED) : TR(LOGRES_UPDATE_FAILED)); GetFacade().ShowFailedPage(); + NotifyAutoReboot(upParams.updateMode); return; } GetFacade().ShowLogRes(TR(LABEL_UPD_OK_DONE)); diff --git a/utils/include/utils_common.h b/utils/include/utils_common.h index de27cc06..cf108560 100644 --- a/utils/include/utils_common.h +++ b/utils/include/utils_common.h @@ -27,6 +27,9 @@ namespace Utils { bool PathToRealPath(const std::string &path, std::string &realPath); void UsSleep(int usec); bool IsUpdaterMode(); +void* LoadLibrary(const std::string &libName, const std::string &libPath); +void CloseLibrary(void* handle); +void* GetFunction(void* handle, const std::string &funcName); } // Utils } // Updater #endif // UTILS_COMMON_H \ No newline at end of file diff --git a/utils/include/utils_fs.h b/utils/include/utils_fs.h index 3170aa6c..a257f81b 100644 --- a/utils/include/utils_fs.h +++ b/utils/include/utils_fs.h @@ -29,9 +29,6 @@ int64_t GetFilesFromDirectory(const std::string &path, std::vector bool RemoveDir(const std::string &path); bool IsFileExist(const std::string &path); bool IsDirExist(const std::string &path); -void* LoadLibrary(const std::string &libName, const std::string &libPath); -void CloseLibrary(void* handle); -void* GetFunction(void* handle, const std::string &funcName); } // Utils } // Updater #endif // UTILS_FS_H \ No newline at end of file diff --git a/utils/utils_common.cpp b/utils/utils_common.cpp index 31186a7a..6c1e7c35 100644 --- a/utils/utils_common.cpp +++ b/utils/utils_common.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -76,5 +77,52 @@ bool IsUpdaterMode() LOG(INFO) << "normal mode"; return false; } + +void* LoadLibrary(const std::string &libName, const std::string &libPath) +{ + if (libName.empty()) { + LOG(ERROR) << "lib name is empty"; + return nullptr; + } + if (libPath != "/system/lib64/" && libPath != "/vendor/lib64/") { + LOG(ERROR) << "lib path invalid"; + return nullptr; + } + std::string libAbsPath = libPath + libName; + char realPath[PATH_MAX + 1] = {0}; + if (realpath(libAbsPath.c_str(), realPath) == nullptr) { + LOG(ERROR) << "realpath error"; + return nullptr; + } + void* handle = dlopen(libAbsPath.c_str(), RTLD_LAZY); + if (handle == nullptr) { + LOG(ERROR) << "dlopen fail, lib name = " << libName << "; dlerror = " << dlerror(); + return nullptr; + } + return handle; +} + +void CloseLibrary(void* handle) +{ + if (handle == nullptr) { + LOG(ERROR) << "handle is nulptr"; + return; + } + dlclose(handle); + handle = nullptr; +} + +void* GetFunction(void* handle, const std::string &funcName) +{ + if (handle == nullptr) { + LOG(ERROR) << "handle is nullptr"; + return nullptr; + } + if (funcName.empty()) { + LOG(ERROR) << "func name is empty"; + return nullptr; + } + return dlsym(handle, funcName.c_str()); +} } // Utils } // updater diff --git a/utils/utils_fs.cpp b/utils/utils_fs.cpp index 28e15433..d14497f3 100644 --- a/utils/utils_fs.cpp +++ b/utils/utils_fs.cpp @@ -149,52 +149,5 @@ bool IsDirExist(const std::string &path) } return false; } - -void* LoadLibrary(const std::string &libName, const std::string &libPath) -{ - if (libName.empty()) { - LOG(ERROR) << "lib name is empty"; - return nullptr; - } - if (libPath != "/system/lib64/" && libPath != "/vendor/lib64/") { - LOG(ERROR) << "lib path invalid"; - return nullptr; - } - std::string libAbsPath = libPath + libName; - char realPath[PATH_MAX + 1] = {0}; - if (realpath(libAbsPath.c_str(), realPath) == nullptr) { - LOG(ERROR) << "realpath error"; - return nullptr; - } - void* handle = dlopen(libAbsPath.c_str(), RTLD_LAZY); - if (handle == nullptr) { - LOG(ERROR) << "dlopen fail, lib name = " << libName << "; dlerror = " << dlerror(); - return nullptr; - } - return handle; -} - -void CloseLibrary(void* handle) -{ - if (handle == nullptr) { - LOG(ERROR) << "handle is nulptr"; - return; - } - dlclose(handle); - handle = nullptr; -} - -void* GetFunction(void* handle, const std::string &funcName) -{ - if (handle == nullptr) { - LOG(ERROR) << "handle is nullptr"; - return nullptr; - } - if (funcName.empty()) { - LOG(ERROR) << "func name is empty"; - return nullptr; - } - return dlsym(handle, funcName.c_str()); -} } // Utils } // updater -- Gitee From 23f3881e1b6927edf7cb094ac054a247fb86145c Mon Sep 17 00:00:00 2001 From: Rayllll Date: Mon, 19 May 2025 09:17:32 +0000 Subject: [PATCH 3/3] update services/updater.cpp. Signed-off-by: Rayllll --- services/updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/updater.cpp b/services/updater.cpp index a41ac4fd..84158f91 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -537,7 +537,7 @@ void ExcuteSubProc(const UpdaterParams &upParams, const std::string &fullPath, i } } const std::string retryPara = upParams.retryCount > 0 ? "retry=1" : "retry=0"; - int ret = 0; + int ret = -1; if (upParams.updateBin.size() > 0) { LOG(INFO) << "Binary Path:" << upParams.updateBin[upParams.pkgLocation].c_str(); ret = execl(fullPath.c_str(), fullPath.c_str(), upParams.updateBin[upParams.pkgLocation].c_str(), -- Gitee