From 9582fcfe54a2b0d661782423a80027b20916e33a Mon Sep 17 00:00:00 2001 From: Caoruihong Date: Wed, 24 May 2023 17:54:22 +0800 Subject: [PATCH] fix: fix checkexit in cold start appspawn Signed-off-by: Caoruihong --- adapter/appspawn_ace.cpp | 7 +++++++ common/appspawn_server.c | 23 +++-------------------- common/appspawn_server.h | 2 ++ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/adapter/appspawn_ace.cpp b/adapter/appspawn_ace.cpp index 99777cea..28c07992 100644 --- a/adapter/appspawn_ace.cpp +++ b/adapter/appspawn_ace.cpp @@ -21,6 +21,7 @@ #include "runtime.h" #include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/app/main_thread.h" +#include "syspara/parameter.h" void LoadExtendLib(AppSpawnContent *content) { @@ -74,6 +75,12 @@ void RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client) { APPSPAWN_LOGI("AppExecFwk::MainThread::Start"); #ifndef APPSPAWN_TEST + std::string checkExit; + if (GetIntParameter("persist.init.debug.checkexit", true)) { + checkExit = std::to_string(getpid()); + } + setenv(APPSPAWN_CHECK_EXIT, checkExit.c_str(), true); OHOS::AppExecFwk::MainThread::Start(); + unsetenv(APPSPAWN_CHECK_EXIT); #endif } diff --git a/common/appspawn_server.c b/common/appspawn_server.c index 3c55b191..1bd1d93f 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -26,10 +26,6 @@ #ifdef OHOS_DEBUG #include #endif // OHOS_DEBUG -#include - -#include "syspara/parameter.h" -#include "securec.h" #define DEFAULT_UMASK 0002 @@ -40,7 +36,6 @@ void DisallowInternet(void); #endif #define SANDBOX_STACK_SIZE (1024 * 1024 * 8) -#define APPSPAWN_CHECK_EXIT "AppSpawnCheckUnexpectedExitCall" static void SetInternetPermission(const AppSpawnClient *client) { @@ -68,7 +63,7 @@ static void NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient * static void ProcessExit(int code) { - APPSPAWN_LOGI("App exit: %{public}d", code); + APPSPAWN_LOGI("App exit code: %{public}d", code); #ifndef APPSPAWN_TEST #ifdef OHOS_LITE _exit(0x7f); // 0x7f user exit @@ -85,7 +80,7 @@ void exit(int code) { char *checkExit = getenv(APPSPAWN_CHECK_EXIT); if (checkExit && atoi(checkExit) == getpid()) { - APPSPAWN_LOGF("Unexpected exit call: %{public}d", code); + APPSPAWN_LOGF("Unexpected call: exit(%{public}d)", code); abort(); } // hook `exit` to `ProcessExit` to ensure app exit in a clean way @@ -148,7 +143,7 @@ int DoStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client, char *l return 0; } -static int AppSpawnChildRun(void *arg) +int AppSpawnChild(void *arg) { APPSPAWN_CHECK(arg != NULL, return -1, "Invalid arg for appspawn child"); AppSandboxArg *sandbox = (AppSandboxArg *)arg; @@ -204,18 +199,6 @@ static int AppSpawnChildRun(void *arg) return 0; } -int AppSpawnChild(void *arg) -{ - char checkExit[16] = ""; // 16 is enough to store an int - if (GetIntParameter("persist.init.debug.checkexit", false)) { - (void)sprintf_s(checkExit, sizeof(checkExit), "%d", getpid()); - } - setenv(APPSPAWN_CHECK_EXIT, checkExit, true); - int ret = AppSpawnChildRun(arg); - unsetenv(APPSPAWN_CHECK_EXIT); - return ret; -} - int AppSpawnProcessMsg(AppSandboxArg *sandbox, pid_t *childPid) { pid_t pid; diff --git a/common/appspawn_server.h b/common/appspawn_server.h index 2df60a5a..00e8242d 100644 --- a/common/appspawn_server.h +++ b/common/appspawn_server.h @@ -37,6 +37,8 @@ extern "C" { #define GID_FILE_ACCESS 1006 // only used for ExternalFileManager.hap #define GID_USER_DATA_RW 1008 +#define APPSPAWN_CHECK_EXIT "AppSpawnCheckUnexpectedExitCall" + typedef struct AppSpawnClient_ { uint32_t id; uint32_t flags; -- Gitee