Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
e8dd40a5
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
大约 1 年 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e8dd40a5
编写于
10月 12, 2022
作者:
O
openharmony_ci
提交者:
Gitee
10月 12, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1355 init log等级设置
Merge pull request !1355 from cheng_jinsong/init1010
上级
485db1ec
ceee295d
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
164 addition
and
7 deletion
+164
-7
interfaces/innerkits/include/beget_ext.h
interfaces/innerkits/include/beget_ext.h
+3
-0
services/begetctl/BUILD.gn
services/begetctl/BUILD.gn
+3
-0
services/begetctl/setloglevel.c
services/begetctl/setloglevel.c
+74
-0
services/log/BUILD.gn
services/log/BUILD.gn
+1
-0
services/log/init_log.c
services/log/init_log.c
+36
-0
services/modules/bootevent/bootevent.c
services/modules/bootevent/bootevent.c
+0
-1
services/modules/init_hook/init_hook.c
services/modules/init_hook/init_hook.c
+44
-4
services/modules/init_hook/param_hook.c
services/modules/init_hook/param_hook.c
+1
-0
services/utils/init_utils.c
services/utils/init_utils.c
+2
-2
未找到文件。
interfaces/innerkits/include/beget_ext.h
浏览文件 @
e8dd40a5
...
...
@@ -52,7 +52,10 @@ typedef void (*InitCommLog)(int logLevel, uint32_t domain, const char *tag, cons
INIT_PUBLIC_API
void
StartupLog
(
InitLogLevel
logLevel
,
uint32_t
domain
,
const
char
*
tag
,
const
char
*
fmt
,
...);
INIT_PUBLIC_API
void
EnableInitLog
(
InitLogLevel
level
);
INIT_PUBLIC_API
void
SetInitLogLevel
(
InitLogLevel
level
);
INIT_PUBLIC_API
int
GetInitLogLevel
(
void
);
INIT_PUBLIC_API
void
SetInitCommLog
(
InitCommLog
logFunc
);
INIT_PUBLIC_API
void
EnableInitLogFromCmdline
(
void
);
#define STARTUP_LOGV(domain, tag, fmt, ...) \
StartupLog(INIT_DEBUG, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
...
...
services/begetctl/BUILD.gn
浏览文件 @
e8dd40a5
...
...
@@ -71,6 +71,7 @@ if (defined(ohos_lite)) {
"param_cmd.c",
"sandbox.cpp",
"service_control.c",
"setloglevel.c",
"shell/shell_bas.c",
]
...
...
@@ -119,6 +120,8 @@ if (defined(ohos_lite)) {
"service",
"sandbox",
"dump_service",
"setloglevel",
"getloglevel",
]
if (enable_ohos_startup_init_feature_ab_partition) {
...
...
services/begetctl/setloglevel.c
0 → 100644
浏览文件 @
e8dd40a5
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "begetctl.h"
#include "init_utils.h"
#include "init_param.h"
#include "securec.h"
#include "shell_utils.h"
static
int32_t
SetInitLogLevelFromParam
(
BShellHandle
shell
,
int
argc
,
char
**
argv
)
{
if
(
argc
!=
2
)
{
// 2 is set log level parameter number
BShellCmdHelp
(
shell
,
argc
,
argv
);
return
0
;
}
errno
=
0
;
unsigned
int
level
=
strtoul
(
argv
[
1
],
0
,
10
);
// 10 is decimal
if
(
errno
!=
0
)
{
printf
(
"Failed to transform %s to unsigned int.
\n
"
,
argv
[
1
]);
return
-
1
;
}
if
((
level
>=
INIT_DEBUG
)
&&
(
level
<=
INIT_FATAL
))
{
int
ret
=
SystemSetParameter
(
"persist.init.debug.loglevel"
,
argv
[
1
]);
if
(
ret
!=
0
)
{
printf
(
"Failed to set log level by param
\"
persist.init.debug.loglevel
\"
%s.
\n
"
,
argv
[
1
]);
}
else
{
printf
(
"Success to set log level by param
\"
persist.init.debug.loglevel
\"
%s.
\n
"
,
argv
[
1
]);
}
}
else
{
printf
(
"Set init log level in invailed parameter %s.
\n
"
,
argv
[
1
]);
}
return
0
;
}
static
int32_t
GetInitLogLevelFromParam
(
BShellHandle
shell
,
int
argc
,
char
**
argv
)
{
char
logLevel
[
2
]
=
{
0
};
// 2 is set param "persist.init.debug.loglevel" value length.
uint32_t
len
=
sizeof
(
logLevel
);
int
ret
=
SystemReadParam
(
"persist.init.debug.loglevel"
,
logLevel
,
&
len
);
if
(
ret
==
0
)
{
printf
(
"Success to get init log level: %s from param
\"
persist.init.debug.loglevel
\"
\n
"
,
logLevel
);
}
else
{
printf
(
"Failed to get init log level from param, keep the system origin log level: %d.
\n
"
,
GetInitLogLevel
());
}
return
0
;
}
MODULE_CONSTRUCTOR
(
void
)
{
const
CmdInfo
infos
[]
=
{
{
"setloglevel"
,
SetInitLogLevelFromParam
,
"set init log level 0:debug, 1:info, 2:warning, 3:err, 4:fatal"
,
"setloglevel level"
,
NULL
},
{
"getloglevel"
,
GetInitLogLevelFromParam
,
"get init log level 0:debug, 1:info, 2:warning, 3:err, 4:fatal"
,
"getloglevel"
,
NULL
},
};
for
(
size_t
i
=
0
;
i
<
sizeof
(
infos
)
/
sizeof
(
infos
[
0
]);
i
++
)
{
BShellEnvRegisterCmd
(
GetShellHandle
(),
&
infos
[
i
]);
}
}
\ No newline at end of file
services/log/BUILD.gn
浏览文件 @
e8dd40a5
...
...
@@ -17,6 +17,7 @@ config("exported_header_files") {
include_dirs = [
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/services/log",
"//base/startup/init/services/include",
]
}
...
...
services/log/init_log.c
浏览文件 @
e8dd40a5
...
...
@@ -22,6 +22,7 @@
#include <time.h>
#include <sys/time.h>
#include "init_utils.h"
#include "securec.h"
#ifdef OHOS_LITE
#ifndef INIT_LOG_INIT
...
...
@@ -131,8 +132,43 @@ INIT_LOCAL_API void InitLog(int logLevel, unsigned int domain, const char *tag,
PrintLog
((
InitLogLevel
)
logLevel
,
domain
,
tag
,
tmpFmt
);
}
INIT_PUBLIC_API
void
SetInitLogLevel
(
InitLogLevel
level
)
{
if
((
level
>=
INIT_DEBUG
)
&&
(
level
<=
INIT_FATAL
))
{
g_logLevel
=
level
;
}
return
;
}
INIT_PUBLIC_API
int
GetInitLogLevel
(
void
)
{
return
g_logLevel
;
}
INIT_PUBLIC_API
void
EnableInitLog
(
InitLogLevel
level
)
{
g_logLevel
=
level
;
SetInitCommLog
(
InitLog
);
}
INIT_PUBLIC_API
void
EnableInitLogFromCmdline
(
void
)
{
SetInitCommLog
(
InitLog
);
char
level
[
MAX_BUFFER_LEN
]
=
{
0
};
char
*
buffer
=
ReadFileData
(
"/proc/cmdline"
);
if
(
buffer
==
NULL
)
{
INIT_LOGE
(
"Failed to read
\"
/proc/cmdline
\"
"
);
return
;
}
int
ret
=
GetProcCmdlineValue
(
"initloglevel"
,
buffer
,
level
,
MAX_BUFFER_LEN
);
free
(
buffer
);
if
(
ret
!=
0
)
{
INIT_LOGE
(
"Failed get log level from cmdline"
);
return
;
}
errno
=
0
;
unsigned
int
logLevel
=
(
unsigned
int
)
strtoul
(
level
,
0
,
10
);
// 10 is decimal
INIT_INFO_CHECK
(
errno
==
0
,
return
,
"Failed strtoul %s, err=%d"
,
level
,
errno
);
SetInitLogLevel
(
logLevel
);
return
;
}
services/modules/bootevent/bootevent.c
浏览文件 @
e8dd40a5
...
...
@@ -342,7 +342,6 @@ static void SetServiceBootEventFork(SERVICE_INFO_CTX *serviceCtx)
MODULE_CONSTRUCTOR
(
void
)
{
EnableInitLog
(
INIT_DEBUG
);
InitAddServiceHook
(
SetServiceBootEventFork
,
INIT_SERVICE_FORK_BEFORE
);
InitAddServiceHook
(
ClearServiceBootEvent
,
INIT_SERVICE_CLEAR
);
InitAddServiceHook
(
DumpServiceBootEvent
,
INIT_SERVICE_DUMP
);
...
...
services/modules/init_hook/init_hook.c
浏览文件 @
e8dd40a5
...
...
@@ -122,9 +122,27 @@ static int CmdClear(int id, const char *name, int argc, const char **argv)
return
0
;
}
static
int
ParamSetBootEventHook
(
const
HOOK_INFO
*
hookInfo
,
void
*
cookie
)
static
int
CmdSetLogLevel
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
if
((
name
==
NULL
)
||
(
argv
==
NULL
)
||
(
argc
<
1
))
{
PLUGIN_LOGE
(
"Failed get log level from parameter."
);
return
-
1
;
}
char
*
value
=
strrchr
(
argv
[
0
],
'.'
);
PLUGIN_CHECK
(
value
!=
NULL
,
return
-
1
,
"Failed get
\'
.
\'
from string %s"
,
argv
[
0
]);
unsigned
int
level
;
int
ret
=
StringToUint
(
value
+
1
,
&
level
);
PLUGIN_CHECK
(
ret
==
0
,
return
-
1
,
"Failed make string to unsigned int"
);
PLUGIN_LOGI
(
"level is %d"
,
level
);
SetInitLogLevel
(
level
);
return
0
;
}
static
int
ParamSetInitCmdHook
(
const
HOOK_INFO
*
hookInfo
,
void
*
cookie
)
{
AddCmdExecutor
(
"clear"
,
CmdClear
);
AddCmdExecutor
(
"setloglevel"
,
CmdSetLogLevel
);
return
0
;
}
...
...
@@ -137,7 +155,7 @@ static int DumpTrigger(const char *fmt, ...)
return
0
;
}
static
int
DumpServiceHook
(
const
HOOK_INFO
*
info
,
void
*
cookie
)
static
void
DumpServiceHook
(
void
)
{
// check and dump all jobs
char
dump
[
8
]
=
{
0
};
// 8 len
...
...
@@ -147,12 +165,34 @@ static int DumpServiceHook(const HOOK_INFO *info, void *cookie)
if
(
ret
==
0
&&
strcmp
(
dump
,
"1"
)
==
0
)
{
SystemDumpTriggers
(
1
,
DumpTrigger
);
}
return
;
}
static
void
InitLogLevelFromPersist
(
void
)
{
char
logLevel
[
2
]
=
{
0
};
// 2 is set param "persist.init.debug.loglevel" value length.
uint32_t
len
=
sizeof
(
logLevel
);
int
ret
=
SystemReadParam
(
"persist.init.debug.loglevel"
,
logLevel
,
&
len
);
INIT_INFO_CHECK
(
ret
==
0
,
return
,
"Can not get log level from param, keep the original loglevel."
);
errno
=
0
;
unsigned
int
level
=
(
unsigned
int
)
strtoul
(
logLevel
,
0
,
10
);
// 10 is decimal
INIT_INFO_CHECK
(
errno
==
0
,
return
,
"Failed strtoul %s, err=%d"
,
logLevel
,
errno
);
SetInitLogLevel
(
level
);
return
;
}
static
int
InitDebugHook
(
const
HOOK_INFO
*
info
,
void
*
cookie
)
{
UNUSED
(
info
);
UNUSED
(
cookie
);
InitLogLevelFromPersist
();
DumpServiceHook
();
return
0
;
}
MODULE_CONSTRUCTOR
(
void
)
{
InitAddGlobalInitHook
(
0
,
ParamSet
BootEvent
Hook
);
InitAddGlobalInitHook
(
0
,
ParamSet
InitCmd
Hook
);
// Depends on parameter service
InitAddPostPersistParamLoadHook
(
0
,
DumpService
Hook
);
InitAddPostPersistParamLoadHook
(
0
,
InitDebug
Hook
);
}
services/modules/init_hook/param_hook.c
浏览文件 @
e8dd40a5
...
...
@@ -62,6 +62,7 @@ const ParamCmdInfo *GetOtherSpecial(size_t *size)
{
static
const
ParamCmdInfo
other
[]
=
{
{
"bootevent."
,
"bootevent."
,
"bootevent"
},
{
"persist.init.debug."
,
"persist.init.debug."
,
"setloglevel"
},
};
*
size
=
ARRAY_LENGTH
(
other
);
return
other
;
...
...
services/utils/init_utils.c
浏览文件 @
e8dd40a5
...
...
@@ -183,7 +183,7 @@ char *ReadFileData(const char *fileName)
int
fd
=
-
1
;
fd
=
open
(
fileName
,
O_RDONLY
);
INIT_ERROR_CHECK
(
fd
>=
0
,
return
NULL
,
"Failed to read file %s"
,
fileName
);
buffer
=
(
char
*
)
malloc
(
MAX_SMALL_BUFFER
);
// fsmanager not create, can not get fileStat st_size
buffer
=
(
char
*
)
calloc
(
1
,
MAX_SMALL_BUFFER
);
// fsmanager not create, can not get fileStat st_size
INIT_ERROR_CHECK
(
buffer
!=
NULL
,
close
(
fd
);
return
NULL
,
"Failed to allocate memory for %s"
,
fileName
);
ssize_t
readLen
=
read
(
fd
,
buffer
,
MAX_SMALL_BUFFER
-
1
);
...
...
@@ -472,7 +472,7 @@ int ReadFileInDir(const char *dirPath, const char *includeExt,
INIT_CHECK_RETURN_VALUE
(
dirPath
!=
NULL
&&
processFile
!=
NULL
,
-
1
);
DIR
*
pDir
=
opendir
(
dirPath
);
INIT_ERROR_CHECK
(
pDir
!=
NULL
,
return
-
1
,
"Read dir :%s failed.%d"
,
dirPath
,
errno
);
char
*
fileName
=
malloc
(
MAX_BUF_SIZE
);
char
*
fileName
=
calloc
(
1
,
MAX_BUF_SIZE
);
INIT_ERROR_CHECK
(
fileName
!=
NULL
,
closedir
(
pDir
);
return
-
1
,
"Failed to malloc for %s"
,
dirPath
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录