mirror of
https://gitee.com/openharmony/startup_init
synced 2025-02-17 10:28:00 +00:00
commit
6b4b555083
@ -67,8 +67,8 @@ typedef enum {
|
||||
ACTION_SANDBOX = 0,
|
||||
ACTION_DUMP,
|
||||
ACTION_MODULEMGR,
|
||||
ACTION_APP_ANDBOX,
|
||||
ACTION_APP_APAWNTIME,
|
||||
ACTION_APP_SANDBOX,
|
||||
ACTION_MAX
|
||||
} ActionType;
|
||||
|
||||
|
@ -16,17 +16,78 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef ENABLE_ENTER_APPSPAWN_SANDBOX
|
||||
#include "appspawn.h"
|
||||
#endif
|
||||
#include "begetctl.h"
|
||||
#include "beget_ext.h"
|
||||
#include "control_fd.h"
|
||||
#include "securec.h"
|
||||
#include "init_param.h"
|
||||
|
||||
#define DUMP_APPSPAWN_CMD_ARGS 1
|
||||
#define DUMP_SERVICE_INFO_CMD_ARGS 2
|
||||
#define DUMP_SERVICE_BOOTEVENT_CMD_ARGS 3
|
||||
|
||||
static int SendAppspawnCmdMessage(const CmdAgent *agent, uint16_t type, const char *cmd, const char *ptyName)
|
||||
{
|
||||
#ifdef ENABLE_ENTER_APPSPAWN_SANDBOX
|
||||
if ((agent == NULL) || (cmd == NULL) || (ptyName == NULL)) {
|
||||
BEGET_LOGE("Invalid parameter");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = -1;
|
||||
AppSpawnClientHandle clientHandle;
|
||||
if (strcmp(cmd, "dump_appspawn") == 0) {
|
||||
ret = AppSpawnClientInit("AppSpawn", &clientHandle);
|
||||
} else if (strcmp(cmd, "dump_nwebspawn") == 0) {
|
||||
ret = AppSpawnClientInit("NWebSpawn", &clientHandle);
|
||||
} else {
|
||||
BEGET_LOGE("Invalid parameter to dump appspawn");
|
||||
}
|
||||
BEGET_ERROR_CHECK(ret == 0, return -1, "AppSpawnClientInit error, errno = %d", errno);
|
||||
AppSpawnReqMsgHandle reqHandle;
|
||||
ret = AppSpawnReqMsgCreate(MSG_DUMP, ptyName, &reqHandle);
|
||||
BEGET_ERROR_CHECK(ret == 0, AppSpawnClientDestroy(clientHandle); return -1, "AppSpawnReqMsgCreate error");
|
||||
ret = AppSpawnReqMsgAddStringInfo(reqHandle, "pty-name", ptyName);
|
||||
BEGET_ERROR_CHECK(ret == 0, AppSpawnClientDestroy(clientHandle);
|
||||
return -1, "add %s request message error", ptyName);
|
||||
AppSpawnResult result = {};
|
||||
ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result);
|
||||
if (ret != 0 || result.result != 0) {
|
||||
AppSpawnClientDestroy(clientHandle);
|
||||
return -1;
|
||||
}
|
||||
AppSpawnClientDestroy(clientHandle);
|
||||
return 0;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void DumpAppspawnClientInit(const char *cmd, CallbackSendMsgProcess sendMsg)
|
||||
{
|
||||
if (cmd == NULL) {
|
||||
BEGET_LOGE("[control_fd] Invalid parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
CmdAgent agent;
|
||||
int ret = InitPtyInterface(&agent, ACTION_DUMP, cmd, sendMsg);
|
||||
if (ret != 0) {
|
||||
BEGET_LOGE("App with pid=%s does not support entering sandbox environment", cmd);
|
||||
return;
|
||||
}
|
||||
LE_RunLoop(LE_GetDefaultLoop());
|
||||
LE_CloseLoop(LE_GetDefaultLoop());
|
||||
BEGET_LOGI("Cmd Client exit ");
|
||||
}
|
||||
|
||||
static int main_cmd(BShellHandle shell, int argc, char **argv)
|
||||
{
|
||||
if (argc == DUMP_SERVICE_INFO_CMD_ARGS) {
|
||||
if (argc == DUMP_APPSPAWN_CMD_ARGS) {
|
||||
DumpAppspawnClientInit(argv[0], SendAppspawnCmdMessage);
|
||||
} else if (argc == DUMP_SERVICE_INFO_CMD_ARGS) {
|
||||
printf("dump service info \n");
|
||||
CmdClientInit(INIT_CONTROL_FD_SOCKET_PATH, ACTION_DUMP, argv[1], NULL);
|
||||
} else if (argc == DUMP_SERVICE_BOOTEVENT_CMD_ARGS) {
|
||||
@ -73,6 +134,8 @@ MODULE_CONSTRUCTOR(void)
|
||||
"bootevent enable"},
|
||||
{"bootevent", BootEventDisable, "bootevent disable", "bootevent disable",
|
||||
"bootevent disable"},
|
||||
{"dump_appspawn", main_cmd, "dump appspawn info", "dump_appspawn", NULL },
|
||||
{"dump_nwebspawn", main_cmd, "dump nwebspawn info", "dump_nwebspawn", NULL}
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(infos) / sizeof(infos[0]); i++) {
|
||||
BShellEnvRegisterCmd(GetShellHandle(), &infos[i]);
|
||||
|
@ -156,7 +156,7 @@ static void CmdAppspawnClientInit(const char *cmd, CallbackSendMsgProcess sendMs
|
||||
}
|
||||
|
||||
CmdAgent agent;
|
||||
int ret = InitPtyInterface(&agent, ACTION_APP_ANDBOX, cmd, sendMsg);
|
||||
int ret = InitPtyInterface(&agent, ACTION_APP_SANDBOX, cmd, sendMsg);
|
||||
if (ret != 0) {
|
||||
BEGET_LOGE("App with pid=%s does not support entering sandbox environment", cmd);
|
||||
return;
|
||||
|
@ -314,6 +314,22 @@ HWTEST_F(BegetctlUnitTest, Init_TestDumpService_005, TestSize.Level1)
|
||||
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast<char **>(args));
|
||||
}
|
||||
|
||||
HWTEST_F(BegetctlUnitTest, Init_TestDumpNwebSpawn_001, TestSize.Level1)
|
||||
{
|
||||
const char *args[] = {
|
||||
"dump_nwebspawn", ""
|
||||
};
|
||||
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast<char **>(args));
|
||||
}
|
||||
|
||||
HWTEST_F(BegetctlUnitTest, Init_TestDumpAppspawn_001, TestSize.Level1)
|
||||
{
|
||||
const char *args[] = {
|
||||
"dump_appspawn", ""
|
||||
};
|
||||
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast<char **>(args));
|
||||
}
|
||||
|
||||
HWTEST_F(BegetctlUnitTest, Init_TestMiscDaemon_001, TestSize.Level1)
|
||||
{
|
||||
const char *args[] = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user