mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-23 07:00:17 +00:00
devicedebug基于错误码打印错误信息
Signed-off-by: 王达 <wangda20@huawei.com>
This commit is contained in:
parent
62acf5459f
commit
fceed2dc74
@ -57,6 +57,21 @@ APPSPAWN_STATIC char* DeviceDebugJsonStringGeneral(int pid, const char *op, cJSO
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
APPSPAWN_STATIC void DevicedebugKillRetDeal(int result, int pid)
|
||||
{
|
||||
switch (result) {
|
||||
case APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_EXIST:
|
||||
printf("devicedebug: kill: %d: No such app process\r\n", pid);
|
||||
break;
|
||||
case APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE:
|
||||
printf("devicedebug: kill: process: %d is not debuggable app\r\n", pid);
|
||||
break;
|
||||
default:
|
||||
printf("devicedebug: process: %d kill unsuccess, please check the hilog for the cause\r\n", pid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal)
|
||||
{
|
||||
cJSON *args = cJSON_CreateObject();
|
||||
@ -106,7 +121,7 @@ APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal)
|
||||
}
|
||||
|
||||
if (result.result != 0) {
|
||||
DEVICEDEBUG_LOGE("devicedebug appspawn kill process unsuccess, result=%{public}d", result.result);
|
||||
DevicedebugKillRetDeal(result.result, pid);
|
||||
return result.result;
|
||||
}
|
||||
|
||||
|
@ -1530,12 +1530,12 @@ APPSPAWN_STATIC int AppspawpnDevicedebugKill(int pid, cJSON *args)
|
||||
AppSpawnedProcess *appInfo = GetSpawnedProcess(pid);
|
||||
if (appInfo == NULL) {
|
||||
APPSPAWN_LOGE("appspawn devicedebug get app info unsuccess, pid=%{public}d", pid);
|
||||
return -1;
|
||||
return APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (!appInfo->isDebuggable) {
|
||||
APPSPAWN_LOGE("appspawn devicedebug process is not debuggable, pid=%{public}d", pid);
|
||||
return -1;
|
||||
return APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE;
|
||||
}
|
||||
|
||||
APPSPAWN_LOGI("appspawn devicedebug debugable=%{public}d, pid=%{public}d, signal=%{public}d",
|
||||
|
@ -552,7 +552,6 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_008, TestSize.Level0)
|
||||
HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_009, TestSize.Level0)
|
||||
{
|
||||
int ret = 0;
|
||||
char pid[16];
|
||||
AppSpawnClientHandle clientHandle = nullptr;
|
||||
AppSpawnResult result = {};
|
||||
do {
|
||||
@ -572,18 +571,28 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_009, TestSize.Level0)
|
||||
|
||||
AppSpawnReqMsgHandle reqHandle2;
|
||||
ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle2);
|
||||
ASSERT_GT(sprintf_s(pid, 16, "%d", app->pid), 0);
|
||||
AppSpawnReqMsgAddStringInfo(reqHandle2, "signal", "-9");
|
||||
AppSpawnReqMsgAddStringInfo(reqHandle2, "pid", pid);
|
||||
cJSON *args = cJSON_CreateObject();
|
||||
ASSERT_NE(args, nullptr);
|
||||
cJSON_AddNumberToObject(args, "signal", 9);
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
ASSERT_NE(root, nullptr);
|
||||
cJSON_AddNumberToObject(root, "app", app->pid);
|
||||
cJSON_AddStringToObject(root, "op", "kill");
|
||||
cJSON_AddItemToObject(root, "args", args);
|
||||
char *jsonString = cJSON_Print(root);
|
||||
cJSON_Delete(root);
|
||||
ret = AppSpawnReqMsgAddExtInfo(reqHandle2, "devicedebug", (uint8_t *)jsonString, strlen(jsonString) + 1);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ret = AppSpawnClientSendMsg(clientHandle, reqHandle2, &result);
|
||||
AppSpawnClientDestroy(clientHandle);
|
||||
free(jsonString);
|
||||
APPSPAWN_CHECK(ret == 0 && result.result == 0, break, "Failed to send msg ret:%{public}d, result:%{public}d",
|
||||
ret, result.result);
|
||||
ASSERT_EQ(kill(app->pid, SIGKILL), 0);
|
||||
} while (0);
|
||||
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(result.result, -1);
|
||||
ASSERT_EQ(result.result, APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE);
|
||||
}
|
||||
|
||||
HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_010, TestSize.Level0)
|
||||
|
@ -131,6 +131,9 @@ typedef enum {
|
||||
APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL,
|
||||
APPSPAWN_SANDBOX_ERROR_SET_PERMISSION_FLAG_FAIL,
|
||||
APPSPAWN_NODE_EXIST,
|
||||
/* devicedebug errno */
|
||||
APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_EXIST,
|
||||
APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE,
|
||||
} AppSpawnErrorCode;
|
||||
|
||||
uint64_t DiffTime(const struct timespec *startTime, const struct timespec *endTime);
|
||||
|
Loading…
Reference in New Issue
Block a user