diff --git a/adapter/appspawn_ace.cpp b/adapter/appspawn_ace.cpp index 99777cea593b9248e1486b8b908de991dc3903a9..28c07992903437ba3984c8d87ee58b7e86f30cd7 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 3c55b191f8d57901af775210b782f2d4d004b2f1..1bd1d93f0ba54e7839060f995e4425be6a19138e 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 2df60a5ae798637a986bde07ae44b9d977ba09ad..00e8242d9f6e70ecb90c0d0a6f5edfd4a4b33f64 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;