diff --git a/standard/appspawn_appmgr.c b/standard/appspawn_appmgr.c index ed1a8daf..6638bc8e 100644 --- a/standard/appspawn_appmgr.c +++ b/standard/appspawn_appmgr.c @@ -137,7 +137,7 @@ static int AppInfoCompareProc(ListNode *node, ListNode *newNode) return node1->pid - node2->pid; } -AppSpawnedProcess *AddSpawnedProcess(pid_t pid, const char *processName) +AppSpawnedProcess *AddSpawnedProcess(pid_t pid, const char *processName, bool isDebuggable) { APPSPAWN_CHECK(g_appSpawnMgr != NULL && processName != NULL, return NULL, "Invalid mgr or process name"); APPSPAWN_CHECK(pid > 0, return NULL, "Invalid pid for %{public}s", processName); @@ -150,6 +150,7 @@ AppSpawnedProcess *AddSpawnedProcess(pid_t pid, const char *processName) node->max = 0; node->uid = 0; node->exitStatus = 0; + node->isDebuggable = isDebuggable; int ret = strcpy_s(node->name, len, processName); APPSPAWN_CHECK(ret == 0, free(node); return NULL, "Failed to strcpy process name"); diff --git a/standard/appspawn_manager.h b/standard/appspawn_manager.h index 6a4c7945..eb261354 100644 --- a/standard/appspawn_manager.h +++ b/standard/appspawn_manager.h @@ -97,6 +97,7 @@ typedef struct TagAppSpawnedProcess { #ifdef DEBUG_BEGETCTL_BOOT AppSpawnMsgNode *message; #endif + bool isDebuggable; char name[0]; } AppSpawnedProcess; @@ -136,7 +137,7 @@ AppSpawnContent *GetAppSpawnContent(void); */ typedef void (*AppTraversal)(const AppSpawnMgr *mgr, AppSpawnedProcess *appInfo, void *data); void TraversalSpawnedProcess(AppTraversal traversal, void *data); -AppSpawnedProcess *AddSpawnedProcess(pid_t pid, const char *processName); +AppSpawnedProcess *AddSpawnedProcess(pid_t pid, const char *processName, bool isDebuggable); AppSpawnedProcess *GetSpawnedProcess(pid_t pid); AppSpawnedProcess *GetSpawnedProcessByName(const char *name); void TerminateSpawnedProcess(AppSpawnedProcess *node); diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 284f67ac..a144287e 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -887,7 +887,8 @@ static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_ return; } // success - AppSpawnedProcess *appInfo = AddSpawnedProcess(property->pid, GetBundleName(property)); + bool isDebuggable = CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE) == 1 ? true : false; + AppSpawnedProcess *appInfo = AddSpawnedProcess(property->pid, GetBundleName(property), isDebuggable); uint32_t len = 0; char *pidMaxStr = NULL; pidMaxStr = GetAppPropertyExt(property, MSG_EXT_NAME_MAX_CHILD_PROCCESS_MAX, &len); @@ -1224,7 +1225,7 @@ AppSpawnContent *StartSpawnService(const AppSpawnStartArg *startArg, uint32_t ar #endif AddAppSpawnHook(STAGE_CHILD_PRE_RUN, HOOK_PRIO_LOWEST, AppSpawnClearEnv); if (arg->mode == MODE_FOR_APP_SPAWN) { - AddSpawnedProcess(pid, NWEBSPAWN_SERVER_NAME); + AddSpawnedProcess(pid, NWEBSPAWN_SERVER_NAME, false); SetParameter("bootevent.appspawn.started", "true"); } return content; @@ -1394,20 +1395,20 @@ static int ProcessAppSpawnDeviceDebugMsg(AppSpawnMsgNode *message) return -1; } - int signal = atoi((char *)GetAppSpawnMsgExtInfo(message, "signal", &len)); + int signal = atoi((char *)GetAppSpawnMsgExtInfo(message, "signal", &len) + 1); if (signal == 0) { APPSPAWN_LOGE("appspawn devicedebug get pid fail"); return -1; } - AppSpawningCtx *property = GetAppSpawningCtxByPid(pid); - if (property == NULL) { - APPSPAWN_LOGE("appspawn devicedebug get property unsuccess, pid=%{public}d", pid); + AppSpawnedProcess *appInfo = GetSpawnedProcess(pid); + if (appInfo == NULL) { + APPSPAWN_LOGE("appspawn devicedebug get app info unsuccess, pid=%{public}d", pid); return -1; } APPSPAWN_LOGI("appspawn devicedebug debugable=%{public}d, pid=%{public}d, signal=%{public}d", - CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE), pid, signal); + appInfo->isDebuggable, pid, signal); if (kill(pid, signal) != 0) { APPSPAWN_LOGE("appspawn devicedebug unable to kill process, pid: %{public}d ret %{public}d", pid, errno); diff --git a/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp index 773f2e92..64787af2 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp @@ -124,7 +124,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnedProcess_001, TestSize.Level0) int result[resultCount] = {0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0}; for (size_t i = 0; i < processNameCount; i++) { for (size_t j = 0; j < pidCount; j++) { - AppSpawnedProcess *app = AddSpawnedProcess(pidInput[j], processNameInput[i]); + AppSpawnedProcess *app = AddSpawnedProcess(pidInput[j], processNameInput[i], false); EXPECT_EQ(app != nullptr, result[i * pidCount + j]); } } @@ -167,7 +167,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnedProcess_002, TestSize.Level0) int result[resultCount] = {0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0}; for (size_t i = 0; i < processNameCount; i++) { for (size_t j = 0; j < pidCount; j++) { - AppSpawnedProcess *app = AddSpawnedProcess(pidInput[j], processNameInput[i]); + AppSpawnedProcess *app = AddSpawnedProcess(pidInput[j], processNameInput[i], false); EXPECT_EQ(app != nullptr, result[i * pidCount + j]); } } @@ -205,7 +205,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnedProcess_003, TestSize.Level0) // GetSpawnedProcessByName size_t processNameCount = ARRAY_LENGTH(processNameInput); for (size_t i = 0; i < processNameCount; i++) { - AppSpawnedProcess *app = AddSpawnedProcess(1000, processNameInput[i]); // 10000 + AppSpawnedProcess *app = AddSpawnedProcess(1000, processNameInput[i], false); // 10000 EXPECT_EQ(app != nullptr, 1); } for (size_t i = 0; i < processNameCount; i++) { @@ -492,7 +492,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_005, TestSize.Level0) EXPECT_EQ(memcmp(buffer.data() + sizeof(AppSpawnMsg), outMsg->buffer, msgLen - sizeof(AppSpawnMsg)), 0); EXPECT_EQ(0, reminder); - AppSpawnedProcess *app = AddSpawnedProcess(9999999, "aaaa"); // 9999999 test + AppSpawnedProcess *app = AddSpawnedProcess(9999999, "aaaa", false); // 9999999 test EXPECT_EQ(app != nullptr, 1); TerminateSpawnedProcess(app); AppSpawnExtData extData; @@ -540,7 +540,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_006, TestSize.Level0) EXPECT_EQ(memcmp(buffer.data() + sizeof(AppSpawnMsg), outMsg->buffer, msgLen - sizeof(AppSpawnMsg)), 0); EXPECT_EQ(0, reminder); - AppSpawnedProcess *app = AddSpawnedProcess(9999999, "aaaa"); // 9999999 test + AppSpawnedProcess *app = AddSpawnedProcess(9999999, "aaaa", false); // 9999999 test EXPECT_EQ(app != nullptr, 1); ret = DecodeAppSpawnMsg(outMsg); diff --git a/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp index a32c3782..f642e3a0 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp @@ -188,7 +188,7 @@ HWTEST_F(AppSpawnModuleInterfaceTest, App_Spawn_Process_Hook_001, TestSize.Level { AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN); EXPECT_EQ(mgr != nullptr, 1); - AppSpawnedProcess *app = AddSpawnedProcess(1000, "test-001"); + AppSpawnedProcess *app = AddSpawnedProcess(1000, "test-001", false); EXPECT_EQ(app != nullptr, 1); int ret = 0;