From 631afe0e5d253dd65598598d5c6721e847a4b91d Mon Sep 17 00:00:00 2001 From: xlei1030 Date: Tue, 1 Mar 2022 14:28:15 +0800 Subject: [PATCH 01/28] =?UTF-8?q?ClientSocket=E7=B1=BB=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=88=90=E5=91=98=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlei1030 --- interfaces/innerkits/include/client_socket.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interfaces/innerkits/include/client_socket.h b/interfaces/innerkits/include/client_socket.h index 7be38b87..dc459bc7 100644 --- a/interfaces/innerkits/include/client_socket.h +++ b/interfaces/innerkits/include/client_socket.h @@ -90,6 +90,7 @@ public: static constexpr int MAX_GIDS = 64; static constexpr int APL_MAX_LEN = 32; static constexpr int RENDER_CMD_MAX_LEN = 1024; + static constexpr int APPSPAWN_COLD_BOOT = 0x01; struct AppProperty { uint32_t uid; // the UNIX uid that the child process setuid() to after fork() @@ -102,6 +103,7 @@ public: uint32_t accessTokenId; char apl[APL_MAX_LEN]; char renderCmd[RENDER_CMD_MAX_LEN]; + uint32_t flags; }; private: -- Gitee From 335ed9525e08d60b7dbf8b16afa13a8cde35eff1 Mon Sep 17 00:00:00 2001 From: xlei1030 Date: Tue, 1 Mar 2022 14:59:48 +0800 Subject: [PATCH 02/28] =?UTF-8?q?=E6=B8=85=E7=90=86=E4=BF=A1=E5=8F=B7?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlei1030 --- src/appspawn_server.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index e5679e6a..def2a98f 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -246,6 +246,17 @@ void AppSpawnServer::LoadAceLib() #endif } + +static void ClearEnvironment(void) +{ + sigset_t mask; + sigemptyset(&mask); + sigaddset(&mask, SIGCHLD); + sigaddset(&mask, SIGTERM); + sigprocmask(SIG_UNBLOCK, &mask, NULL); + return; +} + int AppSpawnServer::StartApp(char *longProcName, int64_t longProcNameLen, ClientSocket::AppProperty *appProperty, int connectFd, pid_t &pid) { @@ -274,6 +285,7 @@ int AppSpawnServer::StartApp(char *longProcName, int64_t longProcNameLen, socket_->CloseServerMonitor(); } close(fd[0]); // close read fd + ClearEnvironment(); UninstallSigHandler(); SetAppProcProperty(appProperty, longProcName, longProcNameLen, fd); _exit(0); @@ -794,14 +806,16 @@ int32_t AppSpawnServer::SetAppSandboxProperty(const ClientSocket::AppProperty *a void AppSpawnServer::SetAppAccessToken(const ClientSocket::AppProperty *appProperty) { int32_t ret = SetSelfTokenID(appProperty->accessTokenId); - if (ret != 0) { - HiLog::Error(LABEL, "AppSpawnServer::Failed to set access token id, errno = %{public}d", errno); - } + HiLog::Info(LABEL, "AppSpawnServer::set access token id = %{public}d, ret = %{public}d", + appProperty->accessTokenId, ret); + #ifdef WITH_SELINUX HapContext hapContext; ret = hapContext.HapDomainSetcontext(appProperty->apl, appProperty->processName); if (ret != 0) { HiLog::Error(LABEL, "AppSpawnServer::Failed to hap domain set context, errno = %{public}d", errno); + } else { + HiLog::Info(LABEL, "AppSpawnServer::Success to hap domain set context, ret = %{public}d", ret); } #endif } -- Gitee From 342cf8841ddc581f3a68a16f6d47899f4ab354fb Mon Sep 17 00:00:00 2001 From: xlei1030 Date: Tue, 1 Mar 2022 15:14:19 +0800 Subject: [PATCH 03/28] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlei1030 --- src/appspawn_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index def2a98f..10bbd2f5 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -253,7 +253,7 @@ static void ClearEnvironment(void) sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigaddset(&mask, SIGTERM); - sigprocmask(SIG_UNBLOCK, &mask, NULL); + sigprocmask(SIG_UNBLOCK, &mask, nullptr); return; } -- Gitee From 0e6424ce4ceafb1c2b14c83a175a347de2b07d00 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 15:27:41 +0800 Subject: [PATCH 04/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- BUILD.gn | 14 +++++++ bundle.json | 1 + src/appspawn_server.cpp | 79 ++++++++++++++++++++++++++++++----- src/include/appspawn_server.h | 6 ++- tools/appspawn_start_app.cpp | 57 +++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 12 deletions(-) create mode 100755 tools/appspawn_start_app.cpp diff --git a/BUILD.gn b/BUILD.gn index 9f0e9b9b..1a1a33e1 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -95,6 +95,20 @@ ohos_static_library("appspawn_server") { part_name = "${part_name}" } +ohos_executable("appspawntools") { + sources = [ "${appspawn_path}/tools/appspawn_start_app.cpp" ] + configs = [ ":appspawn_config" ] + deps = [ + "${appspawn_path}:appspawn_server", + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + install_enable = true + subsystem_name = "${subsystem_name}" + part_name = "${part_name}" +} + ohos_prebuilt_etc("appspawn.rc") { source = "appspawn.cfg" relative_install_dir = "init" diff --git a/bundle.json b/bundle.json index 502b4725..b9972a5b 100644 --- a/bundle.json +++ b/bundle.json @@ -37,6 +37,7 @@ "//base/startup/appspawn_standard:appspawn", "//base/startup/appspawn_standard:appspawn.rc", "//base/startup/appspawn_standard:appspawn_server", + "//base/startup/appspawn_standard:appspawntools", "//base/startup/appspawn_standard:webview", "//base/startup/appspawn_standard/interfaces/innerkits:appspawn_socket_client" ], diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 10bbd2f5..31cf2728 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -246,7 +246,6 @@ void AppSpawnServer::LoadAceLib() #endif } - static void ClearEnvironment(void) { sigset_t mask; @@ -257,6 +256,40 @@ static void ClearEnvironment(void) return; } +int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int fd) +{ + APPSPAWN_LOGI("DoColdStartApp::appName %s", appProperty->processName); + std::vector extractedCmds; + extractedCmds.push_back(const_cast("/system/bin/appspawntools")); + std::string fdStr = std::to_string(fd); + APPSPAWN_LOGI("DoColdStartApp::fd %d %s", fd, fdStr.c_str()); + extractedCmds.push_back(const_cast(fdStr.c_str())); + std::string uidStr = std::to_string(appProperty->uid); + APPSPAWN_LOGI("DoColdStartApp::uid %d %s", appProperty->uid, uidStr.c_str()); + extractedCmds.push_back(const_cast(uidStr.c_str())); + extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gid)).c_str())); + extractedCmds.push_back(const_cast(appProperty->processName)); + extractedCmds.push_back(const_cast(appProperty->bundleName)); + extractedCmds.push_back(const_cast(appProperty->soPath)); + std::string access = std::to_string(appProperty->accessTokenId); + APPSPAWN_LOGI("DoColdStartApp::accessTokenId %d %s", appProperty->accessTokenId, access.c_str()); + extractedCmds.push_back(const_cast(access.c_str())); + extractedCmds.push_back(const_cast(appProperty->apl)); + extractedCmds.push_back(const_cast(appProperty->renderCmd)); + extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->flags)).c_str())); + extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gidCount)).c_str())); + for (uint32_t i = 0; i < appProperty->gidCount; i++) { + extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gidTable[i])).c_str())); + } + extractedCmds.push_back(nullptr); + + int ret = execv(extractedCmds[0], extractedCmds.data()); + if (ret != 0) { + HiLog::Error(LABEL, "Failed to execv, errno = %{public}d", errno); + } + return 0; +} + int AppSpawnServer::StartApp(char *longProcName, int64_t longProcNameLen, ClientSocket::AppProperty *appProperty, int connectFd, pid_t &pid) { @@ -287,7 +320,12 @@ int AppSpawnServer::StartApp(char *longProcName, int64_t longProcNameLen, close(fd[0]); // close read fd ClearEnvironment(); UninstallSigHandler(); - SetAppProcProperty(appProperty, longProcName, longProcNameLen, fd); + appProperty->flags = 1; + if (appProperty->flags == ClientSocket::APPSPAWN_COLD_BOOT) { + DoColdStartApp(appProperty, fd[1]); + } else { + SetAppProcProperty(appProperty, longProcName, longProcNameLen, fd[1]); + } _exit(0); } read(fd[0], &buff, sizeof(buff)); // wait child process resutl @@ -339,7 +377,8 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) appMap_[pid] = appProperty->processName; } socket_->CloseConnection(connectFd); // close socket connection - APPSPAWN_LOGI("AppSpawnServer::parent process create app finish, pid = %d %s", pid, appProperty->processName); + APPSPAWN_LOGI("AppSpawnServer::parent process create app finish, pid = %d uid %d %s %s", + pid, appProperty->uid, appProperty->processName, appProperty->bundleName); } while (appMap_.size() > 0) { @@ -821,21 +860,27 @@ void AppSpawnServer::SetAppAccessToken(const ClientSocket::AppProperty *appPrope } bool AppSpawnServer::SetAppProcProperty(const ClientSocket::AppProperty *appProperty, char *longProcName, - int64_t longProcNameLen, const int32_t fd[FDLEN2]) + int64_t longProcNameLen, const int32_t fd) { + APPSPAWN_LOGI("SetAppProcProperty::bundleName %s", appProperty->bundleName); + APPSPAWN_LOGI("SetAppProcProperty::apl %s", appProperty->apl); + APPSPAWN_LOGI("SetAppProcProperty::uid %d", appProperty->uid); + APPSPAWN_LOGI("SetAppProcProperty::gidCound %d", appProperty->gidCount); + APPSPAWN_LOGI("SetAppProcProperty::accessTokenId %d", appProperty->accessTokenId); + pid_t newPid = getpid(); HiLog::Debug(LABEL, "AppSpawnServer::Success to fork new process, pid = %{public}d", newPid); int32_t ret = ERR_OK; ret = SetAppSandboxProperty(appProperty); if (FAILED(ret)) { - NotifyResToParentProc(fd[1], ret); + NotifyResToParentProc(fd, ret); return false; } ret = SetKeepCapabilities(appProperty->uid); if (FAILED(ret)) { - NotifyResToParentProc(fd[1], ret); + NotifyResToParentProc(fd, ret); return false; } @@ -843,31 +888,31 @@ bool AppSpawnServer::SetAppProcProperty(const ClientSocket::AppProperty *appProp ret = SetProcessName(longProcName, longProcNameLen, appProperty->processName, strlen(appProperty->processName) + 1); if (FAILED(ret)) { - NotifyResToParentProc(fd[1], ret); + NotifyResToParentProc(fd, ret); return false; } #ifdef GRAPHIC_PERMISSION_CHECK ret = SetUidGid(appProperty->uid, appProperty->gid, appProperty->gidTable, appProperty->gidCount); if (FAILED(ret)) { - NotifyResToParentProc(fd[1], ret); + NotifyResToParentProc(fd, ret); return false; } #endif ret = SetFileDescriptors(); if (FAILED(ret)) { - NotifyResToParentProc(fd[1], ret); + NotifyResToParentProc(fd, ret); return false; } ret = SetCapabilities(); if (FAILED(ret)) { - NotifyResToParentProc(fd[1], ret); + NotifyResToParentProc(fd, ret); return false; } // notify success to father process and start app process - NotifyResToParentProc(fd[1], ret); + NotifyResToParentProc(fd, ret); #ifdef WEBVIEW_SPAWN using FuncType = void (*)(const char *cmd); @@ -941,5 +986,17 @@ bool AppSpawnServer::CheckAppProperty(const ClientSocket::AppProperty *appProper return true; } + +int AppSpawnServer::AppColdStart(char *longProcName, + int64_t longProcNameLen, const ClientSocket::AppProperty *appProperty, int fd) +{ + APPSPAWN_LOGI("AppColdStart appName %s", appProperty->bundleName); + LoadAceLib(); + if (!SetAppProcProperty(appProperty, longProcName, longProcNameLen, fd)) { + return -1; + } + APPSPAWN_LOGI("AppColdStart appName %s success", appProperty->bundleName); + return 0; +} } // namespace AppSpawn } // namespace OHOS diff --git a/src/include/appspawn_server.h b/src/include/appspawn_server.h index 6e2192a8..694b3e43 100644 --- a/src/include/appspawn_server.h +++ b/src/include/appspawn_server.h @@ -70,7 +70,11 @@ public: */ void SetServerSocket(const std::shared_ptr &serverSocket); + int AppColdStart(char *longProcName, + int64_t longProcNameLen, const ClientSocket::AppProperty *appProperty, int fd); private: + int DoColdStartApp(ClientSocket::AppProperty *appProperty, int fd); + static constexpr uint8_t BITLEN32 = 32; static constexpr uint8_t FDLEN2 = 2; static constexpr uint8_t FD_INIT_VALUE = 0; @@ -162,7 +166,7 @@ private: * Sets app process property. */ bool SetAppProcProperty(const ClientSocket::AppProperty *appProperty, char *longProcName, - int64_t longProcNameLen, const int32_t fd[FDLEN2]); + int64_t longProcNameLen, const int32_t fd); /** * Notify diff --git a/tools/appspawn_start_app.cpp b/tools/appspawn_start_app.cpp new file mode 100755 index 00000000..80d8ce8a --- /dev/null +++ b/tools/appspawn_start_app.cpp @@ -0,0 +1,57 @@ +#include + +#include "appspawn_server.h" +#include "client_socket.h" +#include "hilog/log.h" +#include "securec.h" + +static const int DECIMAL = 10; + +int main(int argc, char *const argv[]) +{ + if (argc <= 11) { // 11 min argc + printf("appspawntools xxxx \n"); + return 0; + } + + // calculate child process long name size + uintptr_t start = reinterpret_cast(argv[0]); + uintptr_t end = reinterpret_cast(strchr(argv[argc - 1], 0)); + uintptr_t argvSize = end - start; + if (end == 0) { + return 0; + } + + auto appProperty = std::make_unique(); + if (appProperty == nullptr) { + return -1; + } + int index = 1; + int fd = strtoul(argv[index++], nullptr, DECIMAL); + appProperty->uid = strtoul(argv[index++], nullptr, DECIMAL); + appProperty->gid = strtoul(argv[index++], nullptr, DECIMAL); + (void)strcpy_s(appProperty->processName, sizeof(appProperty->processName), argv[index++]); + (void)strcpy_s(appProperty->bundleName, sizeof(appProperty->bundleName), argv[index++]); + (void)strcpy_s(appProperty->soPath, sizeof(appProperty->soPath), argv[index++]); + appProperty->accessTokenId = strtoul(argv[index++], nullptr, DECIMAL); + (void)strcpy_s(appProperty->apl, sizeof(appProperty->apl), argv[index++]); + (void)strcpy_s(appProperty->renderCmd, sizeof(appProperty->renderCmd), argv[index++]); + appProperty->flags = strtoul(argv[index++], nullptr, DECIMAL); + + appProperty->gidCount = strtoul(argv[index++], nullptr, DECIMAL); + uint32_t i = 0; + while (i < appProperty->gidCount && i < sizeof(appProperty->gidTable) / sizeof(sizeof(appProperty->gidTable[0]))) { + if (argv[index] == nullptr) { + break; + } + appProperty->gidTable[i] = strtoul(argv[index++], nullptr, DECIMAL); + } + auto appspawnServer = std::make_shared("AppSpawn"); + if (appspawnServer != nullptr) { + int ret = appspawnServer->AppColdStart(argv[0], argvSize, appProperty.get(), fd); + if (ret != 0) { + printf("Cold start %s fail \n", appProperty->bundleName); + } + } + return 0; +} -- Gitee From 4694a15acf319c6dbc384f5b88621d6f8388e5ef Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 16:30:31 +0800 Subject: [PATCH 05/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 14 ++++--------- tools/appspawn_start_app.cpp | 38 ++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 31cf2728..bb66a485 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -862,14 +862,9 @@ void AppSpawnServer::SetAppAccessToken(const ClientSocket::AppProperty *appPrope bool AppSpawnServer::SetAppProcProperty(const ClientSocket::AppProperty *appProperty, char *longProcName, int64_t longProcNameLen, const int32_t fd) { - APPSPAWN_LOGI("SetAppProcProperty::bundleName %s", appProperty->bundleName); - APPSPAWN_LOGI("SetAppProcProperty::apl %s", appProperty->apl); - APPSPAWN_LOGI("SetAppProcProperty::uid %d", appProperty->uid); - APPSPAWN_LOGI("SetAppProcProperty::gidCound %d", appProperty->gidCount); - APPSPAWN_LOGI("SetAppProcProperty::accessTokenId %d", appProperty->accessTokenId); - - pid_t newPid = getpid(); - HiLog::Debug(LABEL, "AppSpawnServer::Success to fork new process, pid = %{public}d", newPid); + APPSPAWN_LOGI("SetAppProcProperty::bundleName %s accessTokenId %d", + appProperty->bundleName, appProperty->accessTokenId); + HiLog::Debug(LABEL, "AppSpawnServer::Success to fork new process, pid = %{public}d", getpid()); int32_t ret = ERR_OK; ret = SetAppSandboxProperty(appProperty); @@ -885,7 +880,6 @@ bool AppSpawnServer::SetAppProcProperty(const ClientSocket::AppProperty *appProp } SetAppAccessToken(appProperty); - ret = SetProcessName(longProcName, longProcNameLen, appProperty->processName, strlen(appProperty->processName) + 1); if (FAILED(ret)) { NotifyResToParentProc(fd, ret); @@ -926,7 +920,7 @@ bool AppSpawnServer::SetAppProcProperty(const ClientSocket::AppProperty *appProp AppExecFwk::MainThread::Start(); #endif - HiLog::Error(LABEL, "Failed to start process, pid = %{public}d", newPid); + HiLog::Error(LABEL, "Failed to start process, pid = %{public}d", getpid()); return false; } diff --git a/tools/appspawn_start_app.cpp b/tools/appspawn_start_app.cpp index 80d8ce8a..3ae8606d 100755 --- a/tools/appspawn_start_app.cpp +++ b/tools/appspawn_start_app.cpp @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include #include "appspawn_server.h" @@ -5,25 +19,29 @@ #include "hilog/log.h" #include "securec.h" +using namespace OHOS; +using namespace OHOS::HiviewDFX; +static constexpr HiLogLabel LABEL = {LOG_CORE, 0, "AppSpawnServer"}; static const int DECIMAL = 10; int main(int argc, char *const argv[]) { if (argc <= 11) { // 11 min argc - printf("appspawntools xxxx \n"); - return 0; + HiLog::Error(LABEL, "Invalid argc %{public}d", argc); + return -1; } // calculate child process long name size uintptr_t start = reinterpret_cast(argv[0]); uintptr_t end = reinterpret_cast(strchr(argv[argc - 1], 0)); - uintptr_t argvSize = end - start; if (end == 0) { - return 0; + return -1; } + uintptr_t argvSize = end - start; auto appProperty = std::make_unique(); if (appProperty == nullptr) { + HiLog::Error(LABEL, "Failed to create app property %{public}s", argv[2]); return -1; } int index = 1; @@ -37,10 +55,18 @@ int main(int argc, char *const argv[]) (void)strcpy_s(appProperty->apl, sizeof(appProperty->apl), argv[index++]); (void)strcpy_s(appProperty->renderCmd, sizeof(appProperty->renderCmd), argv[index++]); appProperty->flags = strtoul(argv[index++], nullptr, DECIMAL); - + if (index >= argc) { + HiLog::Error(LABEL, "Invalid arg %{public}d %{public}d", index, argc); + return -1; + } appProperty->gidCount = strtoul(argv[index++], nullptr, DECIMAL); + uint32_t i = 0; while (i < appProperty->gidCount && i < sizeof(appProperty->gidTable) / sizeof(sizeof(appProperty->gidTable[0]))) { + if (index >= argc) { + HiLog::Error(LABEL, "Invalid arg %{public}d %{public}d", index, argc); + return -1; + } if (argv[index] == nullptr) { break; } @@ -50,7 +76,7 @@ int main(int argc, char *const argv[]) if (appspawnServer != nullptr) { int ret = appspawnServer->AppColdStart(argv[0], argvSize, appProperty.get(), fd); if (ret != 0) { - printf("Cold start %s fail \n", appProperty->bundleName); + HiLog::Error(LABEL, "Cold start %{public}s fail.", appProperty->bundleName); } } return 0; -- Gitee From 904ff6d25e9276df99d0e3ba71e3c328042e2f92 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 16:34:21 +0800 Subject: [PATCH 06/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- tools/appspawn_start_app.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/appspawn_start_app.cpp b/tools/appspawn_start_app.cpp index 3ae8606d..1ca7fd6d 100755 --- a/tools/appspawn_start_app.cpp +++ b/tools/appspawn_start_app.cpp @@ -62,7 +62,7 @@ int main(int argc, char *const argv[]) appProperty->gidCount = strtoul(argv[index++], nullptr, DECIMAL); uint32_t i = 0; - while (i < appProperty->gidCount && i < sizeof(appProperty->gidTable) / sizeof(sizeof(appProperty->gidTable[0]))) { + while ((i < appProperty->gidCount) && (i < sizeof(appProperty->gidTable) / sizeof(appProperty->gidTable[0]))) { if (index >= argc) { HiLog::Error(LABEL, "Invalid arg %{public}d %{public}d", index, argc); return -1; -- Gitee From 1b5286a33f5f233379242c6b9f19e8fa8616318a Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 16:43:10 +0800 Subject: [PATCH 07/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index bb66a485..532f17a4 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -320,7 +320,7 @@ int AppSpawnServer::StartApp(char *longProcName, int64_t longProcNameLen, close(fd[0]); // close read fd ClearEnvironment(); UninstallSigHandler(); - appProperty->flags = 1; + appProperty->flags = 0; if (appProperty->flags == ClientSocket::APPSPAWN_COLD_BOOT) { DoColdStartApp(appProperty, fd[1]); } else { -- Gitee From 7a8ce5ac55bd66bfadc17663cd46ac08617b8fbd Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 16:45:51 +0800 Subject: [PATCH 08/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 6 +----- tools/appspawn_start_app.cpp | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 532f17a4..15799b0e 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -862,12 +862,8 @@ void AppSpawnServer::SetAppAccessToken(const ClientSocket::AppProperty *appPrope bool AppSpawnServer::SetAppProcProperty(const ClientSocket::AppProperty *appProperty, char *longProcName, int64_t longProcNameLen, const int32_t fd) { - APPSPAWN_LOGI("SetAppProcProperty::bundleName %s accessTokenId %d", - appProperty->bundleName, appProperty->accessTokenId); HiLog::Debug(LABEL, "AppSpawnServer::Success to fork new process, pid = %{public}d", getpid()); - int32_t ret = ERR_OK; - - ret = SetAppSandboxProperty(appProperty); + int32_t ret = SetAppSandboxProperty(appProperty); if (FAILED(ret)) { NotifyResToParentProc(fd, ret); return false; diff --git a/tools/appspawn_start_app.cpp b/tools/appspawn_start_app.cpp index 1ca7fd6d..3ca42a5d 100755 --- a/tools/appspawn_start_app.cpp +++ b/tools/appspawn_start_app.cpp @@ -41,7 +41,7 @@ int main(int argc, char *const argv[]) auto appProperty = std::make_unique(); if (appProperty == nullptr) { - HiLog::Error(LABEL, "Failed to create app property %{public}s", argv[2]); + HiLog::Error(LABEL, "Failed to create app property %{public}s", argv[2]); // 2 name index return -1; } int index = 1; -- Gitee From 260559f7df1a0261627e537c0c18236cc5e229d7 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 17:36:49 +0800 Subject: [PATCH 09/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 15799b0e..71f241d6 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -320,7 +320,7 @@ int AppSpawnServer::StartApp(char *longProcName, int64_t longProcNameLen, close(fd[0]); // close read fd ClearEnvironment(); UninstallSigHandler(); - appProperty->flags = 0; + appProperty->flags = 1; if (appProperty->flags == ClientSocket::APPSPAWN_COLD_BOOT) { DoColdStartApp(appProperty, fd[1]); } else { -- Gitee From 882cb105f025792d564ebe7ba95945840d5c89b7 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 19:58:11 +0800 Subject: [PATCH 10/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 13 ++++++++++--- tools/appspawn_start_app.cpp | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 71f241d6..3f03a42a 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -275,17 +275,23 @@ int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int f APPSPAWN_LOGI("DoColdStartApp::accessTokenId %d %s", appProperty->accessTokenId, access.c_str()); extractedCmds.push_back(const_cast(access.c_str())); extractedCmds.push_back(const_cast(appProperty->apl)); - extractedCmds.push_back(const_cast(appProperty->renderCmd)); + APPSPAWN_LOGI("DoColdStartApp renderCmd %s", appProperty->renderCmd); + if (strlen(appProperty->renderCmd) != 0) { + extractedCmds.push_back(const_cast(appProperty->renderCmd)); + } else { + extractedCmds.push_back(const_cast("")); + } extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->flags)).c_str())); extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gidCount)).c_str())); for (uint32_t i = 0; i < appProperty->gidCount; i++) { extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gidTable[i])).c_str())); } extractedCmds.push_back(nullptr); - + APPSPAWN_LOGI("DoColdStartApp extractedCmds %d", extractedCmds.size()); int ret = execv(extractedCmds[0], extractedCmds.data()); if (ret != 0) { HiLog::Error(LABEL, "Failed to execv, errno = %{public}d", errno); + NotifyResToParentProc(fd, -1); } return 0; } @@ -852,7 +858,8 @@ void AppSpawnServer::SetAppAccessToken(const ClientSocket::AppProperty *appPrope HapContext hapContext; ret = hapContext.HapDomainSetcontext(appProperty->apl, appProperty->processName); if (ret != 0) { - HiLog::Error(LABEL, "AppSpawnServer::Failed to hap domain set context, errno = %{public}d", errno); + HiLog::Error(LABEL, "AppSpawnServer::Failed to hap domain set context, errno = %{public}d %{public}s", + errno, appProperty->apl); } else { HiLog::Info(LABEL, "AppSpawnServer::Success to hap domain set context, ret = %{public}d", ret); } diff --git a/tools/appspawn_start_app.cpp b/tools/appspawn_start_app.cpp index 3ca42a5d..c77231f4 100755 --- a/tools/appspawn_start_app.cpp +++ b/tools/appspawn_start_app.cpp @@ -30,7 +30,7 @@ int main(int argc, char *const argv[]) HiLog::Error(LABEL, "Invalid argc %{public}d", argc); return -1; } - + HiLog::Debug(LABEL, "AppSpawnServer argc %{public}d app:%{public}s", argc, argv[4]); // 4 name index // calculate child process long name size uintptr_t start = reinterpret_cast(argv[0]); uintptr_t end = reinterpret_cast(strchr(argv[argc - 1], 0)); @@ -41,7 +41,7 @@ int main(int argc, char *const argv[]) auto appProperty = std::make_unique(); if (appProperty == nullptr) { - HiLog::Error(LABEL, "Failed to create app property %{public}s", argv[2]); // 2 name index + HiLog::Error(LABEL, "Failed to create app property %{public}s", argv[4]); // 4 name index return -1; } int index = 1; -- Gitee From 70330845ab10ced06b3520855caec5fd9a88f76e Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 21:20:36 +0800 Subject: [PATCH 11/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- tools/appspawn_start_app.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/appspawn_start_app.cpp b/tools/appspawn_start_app.cpp index c77231f4..29194df4 100755 --- a/tools/appspawn_start_app.cpp +++ b/tools/appspawn_start_app.cpp @@ -55,11 +55,8 @@ int main(int argc, char *const argv[]) (void)strcpy_s(appProperty->apl, sizeof(appProperty->apl), argv[index++]); (void)strcpy_s(appProperty->renderCmd, sizeof(appProperty->renderCmd), argv[index++]); appProperty->flags = strtoul(argv[index++], nullptr, DECIMAL); - if (index >= argc) { - HiLog::Error(LABEL, "Invalid arg %{public}d %{public}d", index, argc); - return -1; - } appProperty->gidCount = strtoul(argv[index++], nullptr, DECIMAL); + HiLog::Error(LABEL, "gidCount %{public}d %{public}d", index, appProperty->gidCount); uint32_t i = 0; while ((i < appProperty->gidCount) && (i < sizeof(appProperty->gidTable) / sizeof(appProperty->gidTable[0]))) { @@ -67,10 +64,7 @@ int main(int argc, char *const argv[]) HiLog::Error(LABEL, "Invalid arg %{public}d %{public}d", index, argc); return -1; } - if (argv[index] == nullptr) { - break; - } - appProperty->gidTable[i] = strtoul(argv[index++], nullptr, DECIMAL); + appProperty->gidTable[i++] = strtoul(argv[index++], nullptr, DECIMAL); } auto appspawnServer = std::make_shared("AppSpawn"); if (appspawnServer != nullptr) { -- Gitee From 41dc5915e984d6511b34624ec26f4171290aaa0b Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 22:12:29 +0800 Subject: [PATCH 12/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 3f03a42a..6ff954a0 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -261,28 +261,28 @@ int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int f APPSPAWN_LOGI("DoColdStartApp::appName %s", appProperty->processName); std::vector extractedCmds; extractedCmds.push_back(const_cast("/system/bin/appspawntools")); - std::string fdStr = std::to_string(fd); - APPSPAWN_LOGI("DoColdStartApp::fd %d %s", fd, fdStr.c_str()); - extractedCmds.push_back(const_cast(fdStr.c_str())); - std::string uidStr = std::to_string(appProperty->uid); - APPSPAWN_LOGI("DoColdStartApp::uid %d %s", appProperty->uid, uidStr.c_str()); - extractedCmds.push_back(const_cast(uidStr.c_str())); - extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gid)).c_str())); + std::string tmp = std::to_string(fd); + APPSPAWN_LOGI("DoColdStartApp::fd %d %s", fd, tmp.c_str()); + extractedCmds.push_back(const_cast(tmp.c_str())); + std::string uid = std::to_string(appProperty->uid); + APPSPAWN_LOGI("DoColdStartApp::uid %d gid %d %s", appProperty->uid, appProperty->gid, uid.c_str()); + extractedCmds.push_back(const_cast(uid.c_str())); + std::string gid = std::to_string(appProperty->gid); + extractedCmds.push_back(const_cast(gid.c_str())); extractedCmds.push_back(const_cast(appProperty->processName)); extractedCmds.push_back(const_cast(appProperty->bundleName)); extractedCmds.push_back(const_cast(appProperty->soPath)); - std::string access = std::to_string(appProperty->accessTokenId); - APPSPAWN_LOGI("DoColdStartApp::accessTokenId %d %s", appProperty->accessTokenId, access.c_str()); - extractedCmds.push_back(const_cast(access.c_str())); + std::string accessTokenId = std::to_string(appProperty->accessTokenId); + APPSPAWN_LOGI("DoColdStartApp::accessTokenId %d %s", appProperty->accessTokenId, accessTokenId.c_str()); + extractedCmds.push_back(const_cast(accessTokenId.c_str())); extractedCmds.push_back(const_cast(appProperty->apl)); APPSPAWN_LOGI("DoColdStartApp renderCmd %s", appProperty->renderCmd); - if (strlen(appProperty->renderCmd) != 0) { - extractedCmds.push_back(const_cast(appProperty->renderCmd)); - } else { - extractedCmds.push_back(const_cast("")); - } - extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->flags)).c_str())); - extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gidCount)).c_str())); + extractedCmds.push_back(const_cast(appProperty->renderCmd)); + std::string flags = std::to_string(appProperty->flags); + extractedCmds.push_back(const_cast(flags.c_str())); + std::string gidCount = std::to_string(appProperty->gidCount); + APPSPAWN_LOGI("DoColdStartApp gidCount %d %s", appProperty->gidCount, gidCount.c_str()); + extractedCmds.push_back(const_cast(gidCount.c_str())); for (uint32_t i = 0; i < appProperty->gidCount; i++) { extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gidTable[i])).c_str())); } -- Gitee From 404d0e3f0268a795bf85f10103dd15306f9b8181 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 23:03:45 +0800 Subject: [PATCH 13/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 6 +++--- tools/appspawn_start_app.cpp | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 6ff954a0..59de9544 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -326,6 +326,7 @@ int AppSpawnServer::StartApp(char *longProcName, int64_t longProcNameLen, close(fd[0]); // close read fd ClearEnvironment(); UninstallSigHandler(); + SetAppAccessToken(appProperty); appProperty->flags = 1; if (appProperty->flags == ClientSocket::APPSPAWN_COLD_BOOT) { DoColdStartApp(appProperty, fd[1]); @@ -851,8 +852,8 @@ int32_t AppSpawnServer::SetAppSandboxProperty(const ClientSocket::AppProperty *a void AppSpawnServer::SetAppAccessToken(const ClientSocket::AppProperty *appProperty) { int32_t ret = SetSelfTokenID(appProperty->accessTokenId); - HiLog::Info(LABEL, "AppSpawnServer::set access token id = %{public}d, ret = %{public}d", - appProperty->accessTokenId, ret); + HiLog::Info(LABEL, "AppSpawnServer::set access token id = %{public}d, ret = %{public}d %{public}d", + appProperty->accessTokenId, ret, getuid()); #ifdef WITH_SELINUX HapContext hapContext; @@ -882,7 +883,6 @@ bool AppSpawnServer::SetAppProcProperty(const ClientSocket::AppProperty *appProp return false; } - SetAppAccessToken(appProperty); ret = SetProcessName(longProcName, longProcNameLen, appProperty->processName, strlen(appProperty->processName) + 1); if (FAILED(ret)) { NotifyResToParentProc(fd, ret); diff --git a/tools/appspawn_start_app.cpp b/tools/appspawn_start_app.cpp index 29194df4..072e69f9 100755 --- a/tools/appspawn_start_app.cpp +++ b/tools/appspawn_start_app.cpp @@ -56,8 +56,6 @@ int main(int argc, char *const argv[]) (void)strcpy_s(appProperty->renderCmd, sizeof(appProperty->renderCmd), argv[index++]); appProperty->flags = strtoul(argv[index++], nullptr, DECIMAL); appProperty->gidCount = strtoul(argv[index++], nullptr, DECIMAL); - HiLog::Error(LABEL, "gidCount %{public}d %{public}d", index, appProperty->gidCount); - uint32_t i = 0; while ((i < appProperty->gidCount) && (i < sizeof(appProperty->gidTable) / sizeof(appProperty->gidTable[0]))) { if (index >= argc) { -- Gitee From 0dcfbd0a281a2d5e49d6817009ca5e915e60fd51 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 1 Mar 2022 23:59:48 +0800 Subject: [PATCH 14/28] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 59de9544..4f99f948 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -40,6 +40,7 @@ #include "system_ability_definition.h" #include "token_setproc.h" #include "parameter.h" +#include "parameters.h" #include "beget_ext.h" #ifdef WITH_SELINUX #include "hap_restorecon.h" @@ -327,8 +328,8 @@ int AppSpawnServer::StartApp(char *longProcName, int64_t longProcNameLen, ClearEnvironment(); UninstallSigHandler(); SetAppAccessToken(appProperty); - appProperty->flags = 1; - if (appProperty->flags == ClientSocket::APPSPAWN_COLD_BOOT) { + if ((appProperty->flags == ClientSocket::APPSPAWN_COLD_BOOT) && + OHOS::system::GetBoolParameter("appspawn.cold.boot", false)) { DoColdStartApp(appProperty, fd[1]); } else { SetAppProcProperty(appProperty, longProcName, longProcNameLen, fd[1]); -- Gitee From 613bdd59fa41e17e82d06d4fde4bdd175b00f988 Mon Sep 17 00:00:00 2001 From: xlei1030 Date: Wed, 2 Mar 2022 17:53:57 +0800 Subject: [PATCH 15/28] =?UTF-8?q?Fix:=20=E4=BF=AE=E6=94=B9wagner=20reset?= =?UTF-8?q?=E6=8C=89=E9=94=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlei1030 --- src/appspawn_server.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 4f99f948..322a2d48 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -68,7 +68,7 @@ constexpr int32_t WAIT_DELAY_US = 100 * 1000; // 100ms constexpr int32_t GID_USER_DATA_RW = 1008; constexpr int32_t MAX_GIDS = 64; constexpr int32_t UID_BASE = 200000; -constexpr int32_t WAIT_PARAM_TIME = 1000; +constexpr int32_t WAIT_PARAM_TIME = 5; constexpr std::string_view BUNDLE_NAME_MEDIA_LIBRARY("com.ohos.medialibrary.MediaLibraryDataA"); constexpr std::string_view BUNDLE_NAME_SCANNER("com.ohos.medialibrary.MediaScannerAbilityA"); @@ -171,13 +171,23 @@ void AppSpawnServer::ConnectionPeer() void AppSpawnServer::WaitRebootEvent() { APPSPAWN_LOGI("wait 'startup.device.ctl' event"); + std::string getValue = ""; + int ret = -1; while (isRunning_) { - int ret = WaitParameter("startup.device.ctl", "stop", WAIT_PARAM_TIME); + ret = WaitParameter("startup.device.ctl", "stop", WAIT_PARAM_TIME); if (ret == 0) { std::lock_guard lock(mut_); isStop_ = true; dataCond_.notify_one(); break; + } else { + ret = OHOS::system::GetStringParameter("startup.device.ctl", getValue, ""); + if (ret == 0 && getValue == "stop") { + std::lock_guard lock(mut_); + isStop_ = true; + dataCond_.notify_one(); + break; + } } } } -- Gitee From 11d6ddaa6e48e65382853f7680d320fdd3f08297 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Wed, 2 Mar 2022 19:42:06 +0800 Subject: [PATCH 16/28] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3reset=E6=97=B6?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 322a2d48..743308cb 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -171,18 +171,16 @@ void AppSpawnServer::ConnectionPeer() void AppSpawnServer::WaitRebootEvent() { APPSPAWN_LOGI("wait 'startup.device.ctl' event"); - std::string getValue = ""; - int ret = -1; while (isRunning_) { - ret = WaitParameter("startup.device.ctl", "stop", WAIT_PARAM_TIME); + int ret = WaitParameter("startup.device.ctl", "stop", WAIT_PARAM_TIME); if (ret == 0) { std::lock_guard lock(mut_); isStop_ = true; dataCond_.notify_one(); break; } else { - ret = OHOS::system::GetStringParameter("startup.device.ctl", getValue, ""); - if (ret == 0 && getValue == "stop") { + std::string value = OHOS::system::GetParameter("startup.device.ctl", ""); + if (ret == 0 && value == "stop") { std::lock_guard lock(mut_); isStop_ = true; dataCond_.notify_one(); -- Gitee From 1c62285b150cebaf3da84181f369006aaec2b0e1 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Wed, 2 Mar 2022 21:22:10 +0800 Subject: [PATCH 17/28] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3reset=E6=97=B6?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 743308cb..df76ef36 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -180,7 +180,7 @@ void AppSpawnServer::WaitRebootEvent() break; } else { std::string value = OHOS::system::GetParameter("startup.device.ctl", ""); - if (ret == 0 && value == "stop") { + if (value == "stop") { std::lock_guard lock(mut_); isStop_ = true; dataCond_.notify_one(); -- Gitee From 96e000b4505b4377078061a453d19279875f0ede Mon Sep 17 00:00:00 2001 From: Zheng Yongjun Date: Thu, 3 Mar 2022 20:00:20 +0800 Subject: [PATCH 18/28] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98=201.=E6=8B=BC=E5=86=99=E9=97=AE=E9=A2=98=202?= =?UTF-8?q?.=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90=E4=B8=8D=E5=AF=B9?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=203.=E8=A1=A8=E8=BE=BE=E5=BC=8F?= =?UTF-8?q?=E7=9A=84=E7=AE=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zheng Yongjun --- BUILD.gn | 0 README_zh.md | 0 appspawn.cfg | 0 interfaces/innerkits/BUILD.gn | 0 interfaces/innerkits/include/client_socket.h | 2 +- src/appspawn_server.cpp | 8 ++++---- src/include/appspawn_msg_peer.h | 2 +- src/include/appspawn_server.h | 4 ++-- src/include/server_socket.h | 2 +- src/socket/appspawn_socket.cpp | 0 test/unittest/app_spawn_server_test/BUILD.gn | 0 11 files changed, 9 insertions(+), 9 deletions(-) mode change 100755 => 100644 BUILD.gn mode change 100755 => 100644 README_zh.md mode change 100755 => 100644 appspawn.cfg mode change 100755 => 100644 interfaces/innerkits/BUILD.gn mode change 100755 => 100644 src/socket/appspawn_socket.cpp mode change 100755 => 100644 test/unittest/app_spawn_server_test/BUILD.gn diff --git a/BUILD.gn b/BUILD.gn old mode 100755 new mode 100644 diff --git a/README_zh.md b/README_zh.md old mode 100755 new mode 100644 diff --git a/appspawn.cfg b/appspawn.cfg old mode 100755 new mode 100644 diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn old mode 100755 new mode 100644 diff --git a/interfaces/innerkits/include/client_socket.h b/interfaces/innerkits/include/client_socket.h index dc459bc7..85e979a6 100644 --- a/interfaces/innerkits/include/client_socket.h +++ b/interfaces/innerkits/include/client_socket.h @@ -29,7 +29,7 @@ public: explicit ClientSocket(const std::string &client); /** - * Destructor used to destory a ClientSocket + * Destructor used to destroy a ClientSocket */ virtual ~ClientSocket() = default; diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index df76ef36..e8f61665 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -298,7 +298,7 @@ int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int f extractedCmds.push_back(nullptr); APPSPAWN_LOGI("DoColdStartApp extractedCmds %d", extractedCmds.size()); int ret = execv(extractedCmds[0], extractedCmds.data()); - if (ret != 0) { + if (ret) { HiLog::Error(LABEL, "Failed to execv, errno = %{public}d", errno); NotifyResToParentProc(fd, -1); } @@ -386,7 +386,7 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) ClientSocket::AppProperty *appProperty = msg->GetMsg(); pid_t pid = 0; int ret = StartApp(longProcName, longProcNameLen, appProperty, connectFd, pid); - if (ret != 0) { + if (ret) { msg->Response(ret); } else { msg->Response(pid); @@ -723,7 +723,7 @@ int32_t AppSpawnServer::DoSandboxRootFolderCreateAdapt(std::string sandboxPackag } // bind mount "/" to /mnt/sandbox/ path - // rootfs: to do more resouces bind mount here to get more strict resources constraints + // rootfs: to do more resources bind mount here to get more strict resources constraints rc = mount("/", sandboxPackagePath.c_str(), NULL, MS_BIND | MS_REC, NULL); if (rc) { HiLog::Error(LABEL, "mount bind / failed"); @@ -867,7 +867,7 @@ void AppSpawnServer::SetAppAccessToken(const ClientSocket::AppProperty *appPrope #ifdef WITH_SELINUX HapContext hapContext; ret = hapContext.HapDomainSetcontext(appProperty->apl, appProperty->processName); - if (ret != 0) { + if (ret) { HiLog::Error(LABEL, "AppSpawnServer::Failed to hap domain set context, errno = %{public}d %{public}s", errno, appProperty->apl); } else { diff --git a/src/include/appspawn_msg_peer.h b/src/include/appspawn_msg_peer.h index 0aa10c19..d81b124d 100644 --- a/src/include/appspawn_msg_peer.h +++ b/src/include/appspawn_msg_peer.h @@ -37,7 +37,7 @@ public: AppSpawnMsgPeer(const std::shared_ptr &socket, int connectFd); /** - * Destructor used to destory a AppSpawnMsgPeer + * Destructor used to destroy a AppSpawnMsgPeer */ ~AppSpawnMsgPeer(); diff --git a/src/include/appspawn_server.h b/src/include/appspawn_server.h index 694b3e43..09eb0fad 100644 --- a/src/include/appspawn_server.h +++ b/src/include/appspawn_server.h @@ -39,7 +39,7 @@ public: explicit AppSpawnServer(const std::string &socketName); /** - * Destructor used to destory a AppSpawnServer + * Destructor used to destroy a AppSpawnServer */ ~AppSpawnServer() = default; @@ -93,7 +93,7 @@ private: void ConnectionPeer(); /** - * Sets a name for an applicaiton process. + * Sets a name for an application process. * * @param longProcName Indicates the length of long process name. * @param longProcNameLen Indicates the long process name. diff --git a/src/include/server_socket.h b/src/include/server_socket.h index 84c965cf..8bfe2ce4 100644 --- a/src/include/server_socket.h +++ b/src/include/server_socket.h @@ -34,7 +34,7 @@ public: explicit ServerSocket(const std::string &server); /** - * Destructor used to destory a ServerSocket + * Destructor used to destroy a ServerSocket */ virtual ~ServerSocket(); diff --git a/src/socket/appspawn_socket.cpp b/src/socket/appspawn_socket.cpp old mode 100755 new mode 100644 diff --git a/test/unittest/app_spawn_server_test/BUILD.gn b/test/unittest/app_spawn_server_test/BUILD.gn old mode 100755 new mode 100644 -- Gitee From 561670501b9f5f3cf3b5a8fc5df6b91bb59df6aa Mon Sep 17 00:00:00 2001 From: Zheng Yongjun Date: Thu, 3 Mar 2022 21:39:19 +0800 Subject: [PATCH 19/28] =?UTF-8?q?=E7=BC=A9=E5=86=99/data/bundle=20?= =?UTF-8?q?=E8=83=BD=E8=A2=AB=E7=9C=8B=E5=88=B0=E7=9A=84app=E7=9A=84?= =?UTF-8?q?=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zheng Yongjun --- src/appspawn_server.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) mode change 100644 => 100755 src/appspawn_server.cpp diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp old mode 100644 new mode 100755 index df76ef36..2a6d0373 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -649,14 +649,16 @@ int32_t AppSpawnServer::DoAppSandboxMountCustomized(const ClientSocket::AppPrope std::string currentUserId = std::to_string(appProperty->uid / UID_BASE); std::string destInstallPath = rootPath + "/data/storage/el1/bundle"; - // account_0/applications/ dir can still access other packages' data now for compatibility purpose - std::string oriapplicationsPath = "/data/app/el1/bundle/public/"; - std::string destapplicationsPath = rootPath + "/data/accounts/account_0/applications/"; - DoAppSandboxMountOnce(oriapplicationsPath.c_str(), destapplicationsPath.c_str()); - - // need permission check for system app here - std::string destbundlesPath = rootPath + "/data/bundles/"; - DoAppSandboxMountOnce(oriapplicationsPath.c_str(), destbundlesPath.c_str()); + if (bundleName.find("launcher") != std::string::npos || bundleName.find("systemui") != std::string::npos) { + // account_0/applications/ dir can still access other packages' data now for compatibility purpose + std::string oriapplicationsPath = "/data/app/el1/bundle/public/"; + std::string destapplicationsPath = rootPath + "/data/accounts/account_0/applications/"; + DoAppSandboxMountOnce(oriapplicationsPath.c_str(), destapplicationsPath.c_str()); + + // need permission check for system app here + std::string destbundlesPath = rootPath + "/data/bundles/"; + DoAppSandboxMountOnce(oriapplicationsPath.c_str(), destbundlesPath.c_str()); + } // Add distributedfile module support, later reconstruct it std::string oriDistributedPath = "/mnt/hmdfs/" + currentUserId + "/account/merge_view/data/" + bundleName; -- Gitee From 10e66fffb6987990a6379215116d7c31932ae9aa Mon Sep 17 00:00:00 2001 From: xlei1030 Date: Fri, 4 Mar 2022 10:49:42 +0800 Subject: [PATCH 20/28] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9cppcrash-appspaw?= =?UTF-8?q?n-0-20170806005932?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlei1030 --- src/appspawn_server.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 4f99f948..47574211 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -395,6 +395,7 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) kill(iter->first, SIGKILL); appMap_.erase(iter); } + quick_exit(0); return false; } -- Gitee From 924b153f736c4d84de2a19fd6089756484f3822f Mon Sep 17 00:00:00 2001 From: Zheng Yongjun Date: Fri, 4 Mar 2022 14:41:17 +0800 Subject: [PATCH 21/28] =?UTF-8?q?1,=20=E4=BF=AE=E6=94=B9webview=E4=B8=BAnw?= =?UTF-8?q?eb=202,=20=E7=BC=A9=E5=B0=8F/mnt=E7=9B=AE=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zheng Yongjun --- src/appspawn_server.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index e8f61665..db53a23b 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -53,7 +53,7 @@ #include constexpr static mode_t FILE_MODE = 0711; -constexpr static mode_t WEBVIEW_FILE_MODE = 0511; +constexpr static mode_t NWEB_FILE_MODE = 0511; #define APPSPAWN_LOGI(fmt, ...) STARTUP_LOGI("appspawn_server.log", "APPSPAWN", fmt, ##__VA_ARGS__) #define APPSPAWN_LOGE(fmt, ...) STARTUP_LOGE("appspawn_server.log", "APPSPAWN", fmt, ##__VA_ARGS__) @@ -607,6 +607,7 @@ int32_t AppSpawnServer::DoAppSandboxMount(const ClientSocket::AppProperty *appPr std::string destel1DataPath = rootPath + "/data/storage/el1/base"; std::string destel2DataPath = rootPath + "/data/storage/el2/base"; std::string destappdataPath = rootPath + oriappdataPath; + int rc = 0; std::string bundleName = appProperty->bundleName; @@ -633,7 +634,7 @@ int32_t AppSpawnServer::DoAppSandboxMount(const ClientSocket::AppProperty *appPr // to create some useful dir when mount point created std::vector mkdirInfo; std::string dirPath; - mkdirInfo.push_back("/data/storage/el1/bundle/webview"); + mkdirInfo.push_back("/data/storage/el1/bundle/nweb"); for (int i = 0; i < mkdirInfo.size(); i++) { dirPath = rootPath + mkdirInfo[i]; @@ -658,6 +659,10 @@ int32_t AppSpawnServer::DoAppSandboxMountCustomized(const ClientSocket::AppPrope std::string destbundlesPath = rootPath + "/data/bundles/"; DoAppSandboxMountOnce(oriapplicationsPath.c_str(), destbundlesPath.c_str()); + std::string orimntHmdfsPath = "/mnt/hmdfs/"; + std::string destmntHmdfsPath = rootPath + orimntHmdfsPath; + DoAppSandboxMountOnce(orimntHmdfsPath.c_str(), destmntHmdfsPath.c_str()); + // Add distributedfile module support, later reconstruct it std::string oriDistributedPath = "/mnt/hmdfs/" + currentUserId + "/account/merge_view/data/" + bundleName; std::string destDistributedPath = rootPath + "/data/storage/el2/distributedfiles"; @@ -667,11 +672,11 @@ int32_t AppSpawnServer::DoAppSandboxMountCustomized(const ClientSocket::AppPrope std::string destDistributedGroupPath = rootPath + "/data/storage/el2/auth_groups"; DoAppSandboxMountOnce(oriDistributedGroupPath.c_str(), destDistributedGroupPath.c_str()); - // do webview adaption - std::string oriwebviewPath = "/data/app/el1/bundle/public/com.ohos.webviewhap"; - std::string destwebviewPath = destInstallPath + "/webview"; - chmod(destwebviewPath.c_str(), WEBVIEW_FILE_MODE); - DoAppSandboxMountOnce(oriwebviewPath.c_str(), destwebviewPath.c_str()); + // do nweb adaption + std::string orinwebPath = "/data/app/el1/bundle/public/com.ohos.nweb"; + std::string destnwebPath = destInstallPath + "/nweb"; + chmod(destnwebPath.c_str(), NWEB_FILE_MODE); + DoAppSandboxMountOnce(orinwebPath.c_str(), destnwebPath.c_str()); if (bundleName.find("medialibrary") != std::string::npos) { std::string oriMediaPath = "/storage/media/" + currentUserId; @@ -687,6 +692,8 @@ void AppSpawnServer::DoAppSandboxMkdir(std::string sandboxPackagePath, const Cli std::vector mkdirInfo; std::string dirPath; + mkdirInfo.push_back("/mnt/"); + mkdirInfo.push_back("/mnt/hmdfs/"); mkdirInfo.push_back("/data/"); mkdirInfo.push_back("/storage/"); mkdirInfo.push_back("/storage/media"); @@ -754,7 +761,6 @@ int32_t AppSpawnServer::DoSandboxRootFolderCreate(std::string sandboxPackagePath vecInfo.push_back("/sys"); vecInfo.push_back("/sys-prod"); vecInfo.push_back("/system"); - vecInfo.push_back("/mnt"); for (int i = 0; i < vecInfo.size(); i++) { tmpDir = sandboxPackagePath + vecInfo[i]; -- Gitee From a6c088df87d58d3029c5f180a7f30d587bc94804 Mon Sep 17 00:00:00 2001 From: bigpumpkin Date: Fri, 4 Mar 2022 09:47:01 +0000 Subject: [PATCH 22/28] fix webview name Signed-off-by: @bigpumpkin --- BUILD.gn | 22 +++++++++++----------- appspawn.gni | 2 +- bundle.json | 4 ++-- src/appspawn_server.cpp | 22 +++++++++++----------- src/main.cpp | 2 +- src/socket/server_socket.cpp | 6 +++--- webviewspawn.cfg | 6 +++--- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 1a1a33e1..c59f4a43 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -116,12 +116,12 @@ ohos_prebuilt_etc("appspawn.rc") { part_name = "${part_name}" } -ohos_executable("webviewspawn") { - defines = [ "WEBVIEW_SPAWN" ] +ohos_executable("nwebspawn") { + defines = [ "NWEB_SPAWN" ] sources = [ "${appspawn_path}/src/main.cpp" ] configs = [ ":appspawn_config" ] deps = [ - "${appspawn_path}:webviewspawn_server", + "${appspawn_path}:nwebspawn_server", "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ] @@ -131,10 +131,10 @@ ohos_executable("webviewspawn") { part_name = "${part_name}" } -ohos_static_library("webviewspawn_server") { +ohos_static_library("nwebspawn_server") { defines = [ "INIT_AGENT", - "WEBVIEW_SPAWN", + "NWEB_SPAWN", ] sources = [ "${appspawn_path}/src/appspawn_msg_peer.cpp", @@ -172,19 +172,19 @@ ohos_static_library("webviewspawn_server") { part_name = "${part_name}" } -ohos_prebuilt_etc("webviewspawn.rc") { - source = "webviewspawn.cfg" +ohos_prebuilt_etc("nwebspawn.rc") { + source = "nwebspawn.cfg" relative_install_dir = "init" subsystem_name = "${subsystem_name}" part_name = "${part_name}" } -group("webview") { +group("nweb") { deps = [] - if (appspawn_support_webview) { + if (appspawn_support_nweb) { deps += [ - ":webviewspawn", - ":webviewspawn.rc", + ":nwebspawn", + ":nwebspawn.rc", ] } } diff --git a/appspawn.gni b/appspawn.gni index 5fc789cf..6f978961 100644 --- a/appspawn.gni +++ b/appspawn.gni @@ -21,5 +21,5 @@ part_name = "appspawn" module_output_path = "${part_name}/appspawn_l2" declare_args() { - appspawn_support_webview = true + appspawn_support_nweb = true } diff --git a/bundle.json b/bundle.json index b9972a5b..f7b6d593 100644 --- a/bundle.json +++ b/bundle.json @@ -18,7 +18,7 @@ "standard" ], "features": [ - "appspawn_support_webview" + "appspawn_support_nweb" ], "rom": "", "ram": "", @@ -38,7 +38,7 @@ "//base/startup/appspawn_standard:appspawn.rc", "//base/startup/appspawn_standard:appspawn_server", "//base/startup/appspawn_standard:appspawntools", - "//base/startup/appspawn_standard:webview", + "//base/startup/appspawn_standard:nweb", "//base/startup/appspawn_standard/interfaces/innerkits:appspawn_socket_client" ], "inner_kits": [ diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index b4e29c37..d7eb431d 100755 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -219,8 +219,8 @@ void AppSpawnServer::HandleSignal() void AppSpawnServer::LoadAceLib() { -#ifdef WEBVIEW_SPAWN - std::string enginelibdir("/data/app/el1/bundle/public/com.ohos.webviewhap" +#ifdef NWEB_SPAWN + std::string enginelibdir("/data/app/el1/bundle/public/com.ohos.nweb" "/entry/libs/armeabi/libweb_engine.so"); HiLog::Info(LABEL, "MainThread::LoadAbilityLibrary libweb_engine. Start calling dlopen enginelibdir."); void *handle = dlopen(enginelibdir.c_str(), RTLD_NOW | RTLD_GLOBAL); @@ -231,16 +231,16 @@ void AppSpawnServer::LoadAceLib() } HiLog::Info(LABEL, "MainThread::LoadAbilityLibrary libweb_engine. End calling dlopen."); - std::string execlibdir("/data/app/el1/bundle/public/com.ohos.webviewhap" - "/entry/libs/armeabi/libwebview_exec_proc.so"); - HiLog::Info(LABEL, "MainThread::LoadAbilityLibrary libwebview_exec_proc. Start calling dlopen execlibdir."); - webviewHandle = dlopen(execlibdir.c_str(), RTLD_NOW | RTLD_GLOBAL); - if (webviewHandle == nullptr) { + std::string execlibdir("/data/app/el1/bundle/public/com.ohos.nweb" + "/entry/libs/armeabi/libnweb_render.so"); + HiLog::Info(LABEL, "MainThread::LoadAbilityLibrary libnweb_render. Start calling dlopen execlibdir."); + nwebHandle = dlopen(execlibdir.c_str(), RTLD_NOW | RTLD_GLOBAL); + if (nwebHandle == nullptr) { HiLog::Error(LABEL, "Fail to dlopen %{public}s, [%{public}s]", execlibdir.c_str(), dlerror()); } else { HiLog::Info(LABEL, "Success to dlopen %{public}s", execlibdir.c_str()); } - HiLog::Info(LABEL, "MainThread::LoadAbilityLibrary libwebview_exec_proc. End calling dlopen."); + HiLog::Info(LABEL, "MainThread::LoadAbilityLibrary libnweb_render. End calling dlopen."); #else std::string acelibdir("/system/lib/libace.z.so"); void *AceAbilityLib = nullptr; @@ -928,11 +928,11 @@ bool AppSpawnServer::SetAppProcProperty(const ClientSocket::AppProperty *appProp // notify success to father process and start app process NotifyResToParentProc(fd, ret); -#ifdef WEBVIEW_SPAWN +#ifdef NWEB_SPAWN using FuncType = void (*)(const char *cmd); - FuncType funcWebViewExecuteProcess = reinterpret_cast(dlsym(webviewHandle, "WebViewExecuteProcess")); + FuncType funcWebViewExecuteProcess = reinterpret_cast(dlsym(nwebHandle, "WebViewExecuteProcess")); if (funcWebViewExecuteProcess == nullptr) { - HiLog::Error(LABEL, "webviewspawn dlsym ERROR=%{public}s", dlerror()); + HiLog::Error(LABEL, "nwebspawn dlsym ERROR=%{public}s", dlerror()); return false; } funcWebViewExecuteProcess(appProperty->renderCmd); diff --git a/src/main.cpp b/src/main.cpp index 41e40b2a..63c44633 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,7 @@ int main(int argc, char *const argv[]) uintptr_t argvSize = end - start; #ifdef WEBVIEW_SPAWN - OHOS::AppSpawn::AppSpawnServer appspawnServer("/dev/unix/socket/WebViewSpawn"); + OHOS::AppSpawn::AppSpawnServer appspawnServer("/dev/unix/socket/NwebSpawn"); #else OHOS::AppSpawn::AppSpawnServer appspawnServer("AppSpawn"); #endif diff --git a/src/socket/server_socket.cpp b/src/socket/server_socket.cpp index c7def029..eae7ea45 100644 --- a/src/socket/server_socket.cpp +++ b/src/socket/server_socket.cpp @@ -153,8 +153,8 @@ int ServerSocket::RegisterServerSocket(int &connectFd) return -EINVAL; } -#ifdef WEBVIEW_SPAWN - connectFd = GetControlSocket("WebViewSpawn"); +#ifdef NWEB_SPAWN + connectFd = GetControlSocket("NwebSpawn"); #else connectFd = CreateSocket(); #endif @@ -162,7 +162,7 @@ int ServerSocket::RegisterServerSocket(int &connectFd) return connectFd; } -#ifndef WEBVIEW_SPAWN +#ifndef NWEB_SPAWN if ((BindSocket(connectFd) != 0) || (listen(connectFd, listenBacklog_) < 0)) { HiLog::Error(LABEL, "Server: Register socket fd %d with backlog %d error: %d", diff --git a/webviewspawn.cfg b/webviewspawn.cfg index dc23b829..2b45f595 100644 --- a/webviewspawn.cfg +++ b/webviewspawn.cfg @@ -1,9 +1,9 @@ { "services" : [{ - "name" : "webviewspawn", - "path" : ["/system/bin/webviewspawn"], + "name" : "nwebspawn", + "path" : ["/system/bin/nwebspawn"], "socket" : [{ - "name" : "WebViewSpawn", + "name" : "NwebSpawn", "family" : "AF_LOCAL", "type" : "SOCK_SEQPACKET", "protocol" : "default", -- Gitee From e5bc8e9d8947af0eb2dd441cc0620946fd24bb18 Mon Sep 17 00:00:00 2001 From: bigpumpkin Date: Fri, 4 Mar 2022 09:50:47 +0000 Subject: [PATCH 23/28] fix viewweb to nweb Signed-off-by: @bigpumpkin --- src/include/appspawn_server.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/appspawn_server.h b/src/include/appspawn_server.h index 09eb0fad..ad422eb4 100644 --- a/src/include/appspawn_server.h +++ b/src/include/appspawn_server.h @@ -207,8 +207,8 @@ private: bool isChildDie_ { false }; pid_t childPid_ {}; std::map appMap_; -#ifdef WEBVIEW_SPAWN - void *webviewHandle = nullptr; +#ifdef NWEB_SPAWN + void *nwebHandle = nullptr; #endif }; } // namespace AppSpawn -- Gitee From 7645519768f2cd4d910e07af42b8b06bd98e7228 Mon Sep 17 00:00:00 2001 From: bigpumpkin Date: Fri, 4 Mar 2022 17:53:21 +0800 Subject: [PATCH 24/28] rename webview to nweb Signed-off-by: bigpumpkin --- webviewspawn.cfg => nwebspawn.cfg | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename webviewspawn.cfg => nwebspawn.cfg (100%) diff --git a/webviewspawn.cfg b/nwebspawn.cfg similarity index 100% rename from webviewspawn.cfg rename to nwebspawn.cfg -- Gitee From 9a16323fed049620810524fe29e3991976a291b6 Mon Sep 17 00:00:00 2001 From: bigpumpkin Date: Fri, 4 Mar 2022 18:05:45 +0800 Subject: [PATCH 25/28] fix name Signed-off-by: bigpumpkin --- nwebspawn.cfg | 4 ++-- src/appspawn_server.cpp | 6 +++--- src/main.cpp | 4 ++-- src/socket/server_socket.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nwebspawn.cfg b/nwebspawn.cfg index 2b45f595..7e5dbc73 100644 --- a/nwebspawn.cfg +++ b/nwebspawn.cfg @@ -3,7 +3,7 @@ "name" : "nwebspawn", "path" : ["/system/bin/nwebspawn"], "socket" : [{ - "name" : "NwebSpawn", + "name" : "NWebSpawn", "family" : "AF_LOCAL", "type" : "SOCK_SEQPACKET", "protocol" : "default", @@ -16,4 +16,4 @@ "ondemand" : true } ] -} \ No newline at end of file +} diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index d7eb431d..d8a0cfb7 100755 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -930,12 +930,12 @@ bool AppSpawnServer::SetAppProcProperty(const ClientSocket::AppProperty *appProp #ifdef NWEB_SPAWN using FuncType = void (*)(const char *cmd); - FuncType funcWebViewExecuteProcess = reinterpret_cast(dlsym(nwebHandle, "WebViewExecuteProcess")); - if (funcWebViewExecuteProcess == nullptr) { + FuncType funcNWebRenderMain = reinterpret_cast(dlsym(nwebHandle, "NWebRenderMain")); + if (funcNWebRenderMain == nullptr) { HiLog::Error(LABEL, "nwebspawn dlsym ERROR=%{public}s", dlerror()); return false; } - funcWebViewExecuteProcess(appProperty->renderCmd); + funcNWebRenderMain(appProperty->renderCmd); #else AppExecFwk::MainThread::Start(); #endif diff --git a/src/main.cpp b/src/main.cpp index 63c44633..95ae423a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,8 +26,8 @@ int main(int argc, char *const argv[]) uintptr_t end = reinterpret_cast(strchr(argv[argc - 1], 0)); uintptr_t argvSize = end - start; -#ifdef WEBVIEW_SPAWN - OHOS::AppSpawn::AppSpawnServer appspawnServer("/dev/unix/socket/NwebSpawn"); +#ifdef NWEB_SPAWN + OHOS::AppSpawn::AppSpawnServer appspawnServer("/dev/unix/socket/NWebSpawn"); #else OHOS::AppSpawn::AppSpawnServer appspawnServer("AppSpawn"); #endif diff --git a/src/socket/server_socket.cpp b/src/socket/server_socket.cpp index eae7ea45..7a0b1444 100644 --- a/src/socket/server_socket.cpp +++ b/src/socket/server_socket.cpp @@ -154,7 +154,7 @@ int ServerSocket::RegisterServerSocket(int &connectFd) } #ifdef NWEB_SPAWN - connectFd = GetControlSocket("NwebSpawn"); + connectFd = GetControlSocket("NWebSpawn"); #else connectFd = CreateSocket(); #endif -- Gitee From 1fe680aeb706a6609932dd7493872c4424d55862 Mon Sep 17 00:00:00 2001 From: xlei1030 Date: Mon, 7 Mar 2022 09:35:47 +0800 Subject: [PATCH 26/28] =?UTF-8?q?Fix:=20=E4=BF=AE=E6=94=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E6=89=A7=E8=A1=8C=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlei1030 --- src/appspawn_server.cpp | 2 ++ test/BUILD.gn | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 47574211..5a0b3f19 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -395,7 +395,9 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) kill(iter->first, SIGKILL); appMap_.erase(iter); } +#ifndef TEST_EXIT quick_exit(0); +#endif return false; } diff --git a/test/BUILD.gn b/test/BUILD.gn index 2df1ee15..3e317e94 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -35,7 +35,7 @@ group("moduletest") { config("appspawn_test_config") { configs = [] - defines = [] + defines = ["TEST_EXIT"] include_dirs = [ "${appspawn_path}/test/mock/include", -- Gitee From 7e2b9fded9a9ca8fff0c87e356328e72dbe091f3 Mon Sep 17 00:00:00 2001 From: xlei1030 Date: Mon, 7 Mar 2022 10:39:10 +0800 Subject: [PATCH 27/28] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9D=99=E6=80=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlei1030 --- src/appspawn_server.cpp | 12 +++++++++--- src/include/appspawn_server.h | 2 ++ test/BUILD.gn | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 5a0b3f19..da415ca3 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -344,6 +344,14 @@ int AppSpawnServer::StartApp(char *longProcName, int64_t longProcNameLen, return (buff == ERR_OK) ? 0 : buff; } +void AppSpawnServer::QuickExitMain() +{ +#ifndef TEST_EXIT + quick_exit(0); +#endif + return; +} + bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) { if (socket_->RegisterServerSocket() != 0) { @@ -395,9 +403,7 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) kill(iter->first, SIGKILL); appMap_.erase(iter); } -#ifndef TEST_EXIT - quick_exit(0); -#endif + QuickExitMain(); return false; } diff --git a/src/include/appspawn_server.h b/src/include/appspawn_server.h index 694b3e43..10f491d1 100644 --- a/src/include/appspawn_server.h +++ b/src/include/appspawn_server.h @@ -193,6 +193,8 @@ private: void WaitRebootEvent(); void HandleSignal(); + + void QuickExitMain(); private: const std::string deviceNull_ = "/dev/null"; std::string socketName_ {}; diff --git a/test/BUILD.gn b/test/BUILD.gn index 3e317e94..8bc4665d 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -35,7 +35,7 @@ group("moduletest") { config("appspawn_test_config") { configs = [] - defines = ["TEST_EXIT"] + defines = [ "TEST_EXIT" ] include_dirs = [ "${appspawn_path}/test/mock/include", -- Gitee From edecef1e2da0e7892584f6ac3a63060e75776eee Mon Sep 17 00:00:00 2001 From: Zheng Yongjun Date: Tue, 8 Mar 2022 09:38:19 +0800 Subject: [PATCH 28/28] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20permissionmanager=20?= =?UTF-8?q?=E8=B7=9F=20settings=20=E5=BA=94=E7=94=A8=E7=9A=84=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E5=AE=89=E8=A3=85=E5=8C=85=E8=AE=BF=E9=97=AE=E8=83=BD?= =?UTF-8?q?=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zheng Yongjun --- src/appspawn_server.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) mode change 100755 => 100644 src/appspawn_server.cpp diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp old mode 100755 new mode 100644 index 0bc9c2bd..7fd5ffea --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -659,7 +659,8 @@ int32_t AppSpawnServer::DoAppSandboxMountCustomized(const ClientSocket::AppPrope std::string currentUserId = std::to_string(appProperty->uid / UID_BASE); std::string destInstallPath = rootPath + "/data/storage/el1/bundle"; - if (bundleName.find("launcher") != std::string::npos || bundleName.find("systemui") != std::string::npos) { + if (bundleName.find("launcher") != std::string::npos || bundleName.find("systemui") != std::string::npos ||\ + bundleName.find("permissionmanager") != std::string::npos || bundleName == "com.ohos.settings") { // account_0/applications/ dir can still access other packages' data now for compatibility purpose std::string oriapplicationsPath = "/data/app/el1/bundle/public/"; std::string destapplicationsPath = rootPath + "/data/accounts/account_0/applications/"; -- Gitee