mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-24 08:39:46 +00:00
!1205 解析cfg后,打印trigger信息
Merge pull request !1205 from cheng_jinsong/triggerdump
This commit is contained in:
commit
c96253d21f
@ -359,9 +359,9 @@ static int32_t BShellParamCmdDump(BShellHandle shell, int32_t argc, char *argv[]
|
||||
{
|
||||
BSH_CHECK(shell != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
|
||||
if (argc >= 2 && strcmp(argv[1], "verbose") == 0) { // 2 min arg
|
||||
SystemDumpParameters(1);
|
||||
SystemDumpParameters(1, printf);
|
||||
} else {
|
||||
SystemDumpParameters(0);
|
||||
SystemDumpParameters(0, printf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ void RegisterBootStateChange(void (*bootStateChange)(const char *));
|
||||
* dump 参数和trigger信息
|
||||
*
|
||||
*/
|
||||
void SystemDumpTriggers(int verbose);
|
||||
void SystemDumpTriggers(int verbose, int (*dump)(const char *fmt, ...));
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -217,7 +217,7 @@ int SystemWatchParameter(const char *keyprefix, ParameterChangePtr change, void
|
||||
int SystemCheckParamExist(const char *name);
|
||||
long long GetSystemCommitId(void);
|
||||
|
||||
void SystemDumpParameters(int verbose);
|
||||
void SystemDumpParameters(int verbose, int (*dump)(const char *fmt, ...));
|
||||
|
||||
int WatchParamCheck(const char *keyprefix);
|
||||
|
||||
|
@ -190,7 +190,7 @@ static void ProcessDumpServiceControlFd(uint16_t type, const char *serviceCmd)
|
||||
}
|
||||
if (strcmp(serviceCmd, "parameter_service") == 0) {
|
||||
if (cmd != NULL && strcmp(cmd, "trigger") == 0) {
|
||||
SystemDumpTriggers(0);
|
||||
SystemDumpTriggers(0, printf);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -37,7 +37,10 @@ if (defined(ohos_lite)) {
|
||||
}
|
||||
} else {
|
||||
ohos_source_set("inithook") {
|
||||
defines = [ "_GNU_SOURCE" ]
|
||||
defines = [
|
||||
"_GNU_SOURCE",
|
||||
"PARAM_SUPPORT_TRIGGER",
|
||||
]
|
||||
include_dirs = comm_include
|
||||
sources = [
|
||||
"init_hook.c",
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "securec.h"
|
||||
#include "init_module_engine.h"
|
||||
#include "init_group_manager.h"
|
||||
#include "init_param.h"
|
||||
#include "hookmgr.h"
|
||||
#include "bootstage.h"
|
||||
|
||||
@ -127,7 +128,31 @@ static int ParamSetBootEventHook(const HOOK_INFO *hookInfo, void *cookie)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpTrigger(const char *fmt, ...)
|
||||
{
|
||||
va_list vargs;
|
||||
va_start(vargs, fmt);
|
||||
InitLog(INIT_INFO, INIT_LOG_DOMAIN, INIT_LOG_TAG, fmt, vargs);
|
||||
va_end(vargs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpServiceHook(const HOOK_INFO *info, void *cookie)
|
||||
{
|
||||
// check and dump all jobs
|
||||
char dump[8] = {0}; // 8 len
|
||||
uint32_t len = sizeof(dump);
|
||||
int ret = SystemReadParam("persist.init.debug.dump.trigger", dump, &len);
|
||||
PLUGIN_LOGV("boot dump %s ret %d", dump, ret);
|
||||
if (ret == 0 && strcmp(dump, "1") == 0) {
|
||||
SystemDumpTriggers(1, DumpTrigger);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MODULE_CONSTRUCTOR(void)
|
||||
{
|
||||
InitAddGlobalInitHook(0, ParamSetBootEventHook);
|
||||
// Depends on parameter service
|
||||
InitAddPostPersistParamLoadHook(0, DumpServiceHook);
|
||||
}
|
||||
|
@ -36,6 +36,10 @@ ohos_shared_library("rebootmodule") {
|
||||
} else {
|
||||
module_install_dir = "lib/init"
|
||||
}
|
||||
install_images = [
|
||||
"system",
|
||||
"updater",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_source_set("libreboot_static") {
|
||||
|
@ -129,7 +129,8 @@ INIT_LOCAL_API void ParamWorBaseLog(InitLogLevel logLevel, uint32_t domain, cons
|
||||
exper; \
|
||||
}
|
||||
|
||||
#define PARAM_DUMP printf
|
||||
typedef int (*DUMP_PRINTF)(const char *fmt, ...);
|
||||
#define PARAM_DUMP g_printf
|
||||
#define MAX_LABEL_LEN 256
|
||||
#define PARAM_BUFFER_SIZE 256
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "param_trie.h"
|
||||
#include "param_utils.h"
|
||||
#include "securec.h"
|
||||
static DUMP_PRINTF g_printf = printf;
|
||||
|
||||
ParamNode *SystemCheckMatchParamWait(const char *name, const char *value)
|
||||
{
|
||||
@ -162,8 +163,13 @@ static void HashNodeTraverseForDump(WorkSpace *workSpace, int verbose)
|
||||
PARAMSPACE_AREA_RW_UNLOCK(workSpace);
|
||||
}
|
||||
|
||||
void SystemDumpParameters(int verbose)
|
||||
void SystemDumpParameters(int verbose, int (*dump)(const char *fmt, ...))
|
||||
{
|
||||
if (dump != NULL) {
|
||||
g_printf = dump;
|
||||
} else {
|
||||
g_printf = printf;
|
||||
}
|
||||
ParamWorkSpace *paramSpace = GetParamWorkSpace();
|
||||
PARAM_CHECK(paramSpace != NULL, return, "Invalid paramSpace");
|
||||
PARAM_WORKSPACE_CHECK(paramSpace, return, "Invalid space");
|
||||
@ -173,10 +179,16 @@ void SystemDumpParameters(int verbose)
|
||||
if (ret != PARAM_CODE_NOT_FOUND && ret != 0 && ret != PARAM_CODE_NODE_EXIST) {
|
||||
PARAM_CHECK(ret == 0, return, "Forbid to dump parameters");
|
||||
}
|
||||
#ifdef PARAM_SUPPORT_SELINUX // load security label
|
||||
ParamSecurityOps *ops = GetParamSecurityOps(PARAM_SECURITY_SELINUX);
|
||||
if (ops != NULL && ops->securityGetLabel != NULL) {
|
||||
ops->securityGetLabel(NULL);
|
||||
}
|
||||
#endif
|
||||
PARAM_DUMP("Dump all parameters begin ...\n");
|
||||
if (verbose) {
|
||||
PARAM_DUMP("Local sercurity information\n");
|
||||
PARAM_DUMP("\t pid: %d uid: %u gid: %u \n",
|
||||
PARAM_DUMP("pid: %d uid: %u gid: %u \n",
|
||||
paramSpace->securityLabel.cred.pid,
|
||||
paramSpace->securityLabel.cred.uid,
|
||||
paramSpace->securityLabel.cred.gid);
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "trigger_checker.h"
|
||||
#include "securec.h"
|
||||
|
||||
static DUMP_PRINTF g_printf = printf;
|
||||
|
||||
int AddCommand(JobNode *trigger, uint32_t cmdKeyIndex, const char *content)
|
||||
{
|
||||
PARAM_CHECK(trigger != NULL, return -1, "trigger is null");
|
||||
@ -41,7 +43,7 @@ int AddCommand(JobNode *trigger, uint32_t cmdKeyIndex, const char *content)
|
||||
PARAM_CHECK(ret == EOK, free(node);
|
||||
return 0, "Failed to copy command");
|
||||
}
|
||||
// 插入队列
|
||||
|
||||
if (trigger->firstCmd == NULL) {
|
||||
trigger->firstCmd = node;
|
||||
trigger->lastCmd = node;
|
||||
@ -518,8 +520,13 @@ static void DumpTrigger_(const TriggerWorkSpace *workSpace, int type)
|
||||
}
|
||||
}
|
||||
|
||||
void SystemDumpTriggers(int verbose)
|
||||
void SystemDumpTriggers(int verbose, int (*dump)(const char *fmt, ...))
|
||||
{
|
||||
if (dump != NULL) {
|
||||
g_printf = dump;
|
||||
} else {
|
||||
g_printf = printf;
|
||||
}
|
||||
TriggerWorkSpace *workSpace = GetTriggerWorkSpace();
|
||||
PARAM_CHECK(workSpace != NULL, return, "Invalid workSpace ");
|
||||
PARAM_DUMP("workspace queue BOOT info:\n");
|
||||
|
@ -24,7 +24,7 @@ namespace OHOS {
|
||||
CloseStdout();
|
||||
std::string str(reinterpret_cast<const char*>(data), size);
|
||||
int verbose = atoi(str.c_str());
|
||||
SystemDumpParameters(verbose);
|
||||
SystemDumpParameters(verbose, nullptr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ HWTEST_F(ClientUnitTest, TestClient_03, TestSize.Level0)
|
||||
{
|
||||
// 3 Traversal test
|
||||
TestParamTraversal();
|
||||
SystemDumpParameters(1);
|
||||
SystemDumpParameters(1, NULL);
|
||||
}
|
||||
|
||||
HWTEST_F(ClientUnitTest, TestClient_04, TestSize.Level0)
|
||||
|
@ -298,7 +298,7 @@ public:
|
||||
|
||||
int TestDumpParamMemory()
|
||||
{
|
||||
SystemDumpParameters(1);
|
||||
SystemDumpParameters(1, NULL);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
@ -429,7 +429,7 @@ public:
|
||||
char buffer[] = "testbuff";
|
||||
CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM_WATCH, buffer, strlen(buffer), TestTriggerExecute);
|
||||
#ifdef PARAM_SUPPORT_TRIGGER
|
||||
SystemDumpTriggers(1);
|
||||
SystemDumpTriggers(1, NULL);
|
||||
#endif
|
||||
AddWatch(MSG_DEL_WATCHER, name, value);
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user