Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
cde18501
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,发现更多精彩内容 >>
提交
cde18501
编写于
10月 17, 2022
作者:
C
cheng_jinsong
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://gitee.com/chneg-jinsong/startup_init_lite_sf1017
into init1017
上级
67e849cd
702e2df0
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
295 addition
and
99 deletion
+295
-99
interfaces/innerkits/fs_manager/fstab_mount.c
interfaces/innerkits/fs_manager/fstab_mount.c
+2
-2
interfaces/innerkits/init_module_engine/include/init_cmdexecutor.h
...s/innerkits/init_module_engine/include/init_cmdexecutor.h
+2
-0
interfaces/innerkits/init_module_engine/stub/libinit.stub.json
...faces/innerkits/init_module_engine/stub/libinit.stub.json
+2
-1
interfaces/innerkits/modulemgr/modulemgr.c
interfaces/innerkits/modulemgr/modulemgr.c
+27
-21
services/init/standard/init_reboot.c
services/init/standard/init_reboot.c
+5
-0
services/modules/init_hook/BUILD.gn
services/modules/init_hook/BUILD.gn
+4
-1
services/modules/init_hook/init_hook.h
services/modules/init_hook/init_hook.h
+3
-3
services/modules/init_hook/param_hook.c
services/modules/init_hook/param_hook.c
+2
-1
services/modules/reboot/reboot.c
services/modules/reboot/reboot.c
+30
-42
services/modules/reboot/reboot_static.c
services/modules/reboot/reboot_static.c
+113
-7
services/param/linux/param_service.c
services/param/linux/param_service.c
+1
-1
services/param/manager/param_manager.c
services/param/manager/param_manager.c
+26
-9
services/param/trigger/trigger_checker.c
services/param/trigger/trigger_checker.c
+14
-2
services/param/trigger/trigger_manager.c
services/param/trigger/trigger_manager.c
+1
-2
test/moduletest/param_test_cmds.c
test/moduletest/param_test_cmds.c
+7
-7
test/unittest/BUILD.gn
test/unittest/BUILD.gn
+2
-0
test/unittest/init/init_reboot_unittest.cpp
test/unittest/init/init_reboot_unittest.cpp
+54
-0
未找到文件。
interfaces/innerkits/fs_manager/fstab_mount.c
浏览文件 @
cde18501
...
...
@@ -107,11 +107,11 @@ int DoFormat(const char *devPath, const char *fsType)
}
else
if
(
strcmp
(
fsType
,
"f2fs"
)
==
0
)
{
#ifdef __MUSL__
char
*
formatCmds
[]
=
{
"/bin/mkfs.f2fs"
,
(
char
*
)
devPath
,
NULL
"/bin/mkfs.f2fs"
,
"-d1"
,
"-O"
,
"encrypt"
,
"-O"
,
"quota"
,
"-O"
,
"verity"
,
(
char
*
)
devPath
,
NULL
};
#else
char
*
formatCmds
[]
=
{
"/bin/make_f2fs"
,
(
char
*
)
devPath
,
NULL
"/bin/make_f2fs"
,
"-d1"
,
"-O"
,
"encrypt"
,
"-O"
,
"quota"
,
"-O"
,
"verity"
,
(
char
*
)
devPath
,
NULL
};
#endif
int
argc
=
ARRAY_LENGTH
(
formatCmds
);
...
...
interfaces/innerkits/init_module_engine/include/init_cmdexecutor.h
浏览文件 @
cde18501
...
...
@@ -46,6 +46,8 @@ const char *GetPluginCmdNameByIndex(int index);
int
AddCmdExecutor
(
const
char
*
cmdName
,
CmdExecutor
execCmd
);
int
AddRebootCmdExecutor
(
const
char
*
cmd
,
CmdExecutor
executor
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
interfaces/innerkits/init_module_engine/stub/libinit.stub.json
浏览文件 @
cde18501
...
...
@@ -17,5 +17,6 @@
{
"name"
:
"StartupLog"
},
{
"name"
:
"DoJobNow"
},
{
"name"
:
"GetServiceExtData"
},
{
"name"
:
"UpdateMiscMessage"
}
{
"name"
:
"UpdateMiscMessage"
},
{
"name"
:
"AddRebootCmdExecutor"
}
]
interfaces/innerkits/modulemgr/modulemgr.c
浏览文件 @
cde18501
...
...
@@ -33,6 +33,7 @@
#else
#define MODULE_LIB_NAME "lib"
#endif
#define LIB_NAME_LEN 3
struct
tagMODULE_MGR
{
ListNode
modules
;
...
...
@@ -103,9 +104,9 @@ static void *ModuleInstall(MODULE_ITEM *module, int argc, const char *argv[])
module
->
moduleMgr
->
installArgs
.
argc
=
argc
;
module
->
moduleMgr
->
installArgs
.
argv
=
argv
;
if
(
module
->
moduleMgr
->
name
[
0
]
==
'/'
)
{
if
(
snprintf_s
(
path
,
sizeof
(
path
),
sizeof
(
path
)
-
1
,
"%s/%s"
MODULE_SUFFIX_D
,
module
->
moduleMgr
->
name
,
module
->
name
)
<
0
)
{
BEGET_LOGV
(
"Module install name %s"
,
module
->
name
);
if
(
module
->
name
[
0
]
==
'/'
)
{
if
(
snprintf_s
(
path
,
sizeof
(
path
),
sizeof
(
path
)
-
1
,
"%s"
MODULE_SUFFIX_D
,
module
->
name
)
<
0
)
{
return
NULL
;
}
}
else
{
...
...
@@ -126,8 +127,14 @@ static void *ModuleInstall(MODULE_ITEM *module, int argc, const char *argv[])
static
int
ModuleCompare
(
ListNode
*
node
,
void
*
data
)
{
MODULE_ITEM
*
module
=
(
MODULE_ITEM
*
)
node
;
return
strcmp
(
module
->
name
,
(
char
*
)
data
);
const
char
*
name
=
module
->
name
;
if
(
module
->
name
[
0
]
==
'/'
)
{
name
=
strrchr
((
name
),
'/'
)
+
1
;
}
if
(
strncmp
(
name
,
"lib"
,
LIB_NAME_LEN
)
==
0
)
{
name
=
name
+
LIB_NAME_LEN
;
}
return
strcmp
(
name
,
(
char
*
)
data
);
}
/*
...
...
@@ -160,7 +167,7 @@ int ModuleMgrInstall(MODULE_MGR *moduleMgr, const char *moduleName,
// Install
module
->
handle
=
ModuleInstall
(
module
,
argc
,
argv
);
if
(
module
->
handle
==
NULL
)
{
BEGET_LOGE
(
"Failed to install module %s"
,
module
N
ame
);
BEGET_LOGE
(
"Failed to install module %s"
,
module
->
n
ame
);
ModuleDestroy
((
ListNode
*
)
module
);
return
-
1
;
}
...
...
@@ -190,15 +197,12 @@ static int StringEndsWith(const char *srcStr, const char *endStr)
static
void
ScanModules
(
MODULE_MGR
*
moduleMgr
,
const
char
*
path
)
{
int
end
;
DIR
*
dir
;
struct
dirent
*
file
;
dir
=
opendir
(
path
);
BEGET_LOGV
(
"Scan module with name '%s'"
,
path
);
DIR
*
dir
=
opendir
(
path
);
BEGET_CHECK
(
dir
!=
NULL
,
return
);
while
(
1
)
{
file
=
readdir
(
dir
);
char
*
moduleName
=
malloc
(
PATH_MAX
);
while
(
moduleName
!=
NULL
)
{
struct
dirent
*
file
=
readdir
(
dir
);
if
(
file
==
NULL
)
{
break
;
}
...
...
@@ -207,20 +211,22 @@ static void ScanModules(MODULE_MGR *moduleMgr, const char *path)
}
// Must be ended with MODULE_SUFFIX_D
end
=
StringEndsWith
(
file
->
d_name
,
MODULE_SUFFIX_D
);
int
end
=
StringEndsWith
(
file
->
d_name
,
MODULE_SUFFIX_D
);
if
(
end
<=
0
)
{
continue
;
}
file
->
d_name
[
end
]
=
'\0'
;
BEGET_LOGV
(
"Scan module with name %s"
,
file
->
d_name
);
if
(
strncmp
(
file
->
d_name
,
"lib"
,
strlen
(
"lib"
))
==
0
)
{
ModuleMgrInstall
(
moduleMgr
,
file
->
d_name
+
strlen
(
"lib"
),
0
,
NULL
)
;
}
else
{
ModuleMgrInstall
(
moduleMgr
,
file
->
d_n
ame
,
0
,
NULL
);
int
len
=
sprintf_s
(
moduleName
,
PATH_MAX
-
1
,
"%s/%s"
,
path
,
file
->
d_name
);
if
(
len
>
0
)
{
moduleName
[
len
]
=
'\0'
;
BEGET_LOGI
(
"Scan module with name '%s'"
,
moduleName
);
ModuleMgrInstall
(
moduleMgr
,
moduleN
ame
,
0
,
NULL
);
}
}
if
(
moduleName
!=
NULL
)
{
free
(
moduleName
);
}
closedir
(
dir
);
}
...
...
services/init/standard/init_reboot.c
浏览文件 @
cde18501
...
...
@@ -17,11 +17,16 @@
#include "init_cmdexecutor.h"
#include "init_log.h"
#include "init_group_manager.h"
#include "init_modulemgr.h"
void
ExecReboot
(
const
char
*
value
)
{
INIT_LOGI
(
"ExecReboot %s"
,
value
);
#ifndef STARTUP_INIT_TEST
// install module
InitModuleMgrInstall
(
"rebootmodule"
);
PluginExecCmdByName
(
"reboot"
,
value
);
#endif
return
;
}
...
...
services/modules/init_hook/BUILD.gn
浏览文件 @
cde18501
...
...
@@ -30,7 +30,10 @@ comm_include = [
]
if (defined(ohos_lite)) {
static_library("inithook") {
defines = [ "_GNU_SOURCE" ]
defines = [
"_GNU_SOURCE",
"OHOS_LITE",
]
include_dirs = comm_include
sources = [ "param_hook.c" ]
public_configs = [ ":inithook_config" ]
...
...
services/modules/init_hook/init_hook.h
浏览文件 @
cde18501
...
...
@@ -28,9 +28,9 @@ extern "C" {
#define SERVICE_CTL_CMD_INDEX 2
typedef
struct
{
c
onst
c
har
*
name
;
// system parameter partial name
c
onst
c
har
*
replace
;
// replace content if filed name match system parameter
c
onst
c
har
*
cmd
;
// command name
char
*
name
;
// system parameter partial name
char
*
replace
;
// replace content if filed name match system parameter
char
*
cmd
;
// command name
}
ParamCmdInfo
;
const
ParamCmdInfo
*
GetServiceStartCtrl
(
size_t
*
size
);
...
...
services/modules/init_hook/param_hook.c
浏览文件 @
cde18501
...
...
@@ -43,19 +43,20 @@ const ParamCmdInfo *GetServiceCtl(size_t *size)
return
installParam
;
}
#ifdef OHOS_LITE
const
ParamCmdInfo
*
GetStartupPowerCtl
(
size_t
*
size
)
{
static
const
ParamCmdInfo
powerCtrlArg
[]
=
{
{
"reboot,shutdown"
,
"reboot.shutdown"
,
"reboot.shutdown"
},
{
"reboot,updater"
,
"reboot.updater"
,
"reboot.updater"
},
{
"reboot,flashd"
,
"reboot.flashd"
,
"reboot.flashd"
},
{
"reboot,loader"
,
"reboot.loader"
,
"reboot.loader"
},
{
"reboot,charge"
,
"reboot.charge"
,
"reboot.charge"
},
{
"reboot"
,
"reboot"
,
"reboot"
},
};
*
size
=
ARRAY_LENGTH
(
powerCtrlArg
);
return
powerCtrlArg
;
}
#endif
const
ParamCmdInfo
*
GetOtherSpecial
(
size_t
*
size
)
{
...
...
services/modules/reboot/reboot.c
浏览文件 @
cde18501
...
...
@@ -20,12 +20,6 @@
#include "plugin_adapter.h"
#include "securec.h"
typedef
struct
{
const
char
*
cmd
;
CmdExecutor
executor
;
uint32_t
cmdId
;
}
ModuleCmdInfo
;
static
int
DoRoot_
(
const
char
*
jobName
,
int
type
)
{
// by job to stop service and unmount
...
...
@@ -34,11 +28,17 @@ static int DoRoot_(const char *jobName, int type)
}
#ifndef STARTUP_INIT_TEST
return
reboot
(
type
);
#else
return
0
;
#endif
}
static
int
DoReboot
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
UNUSED
(
name
);
UNUSED
(
argc
);
UNUSED
(
argv
);
// clear misc
(
void
)
UpdateMiscMessage
(
NULL
,
"reboot"
,
NULL
,
NULL
);
return
DoRoot_
(
"reboot"
,
RB_AUTOBOOT
);
...
...
@@ -46,6 +46,10 @@ static int DoReboot(int id, const char *name, int argc, const char **argv)
static
int
DoRebootShutdown
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
UNUSED
(
name
);
UNUSED
(
argc
);
UNUSED
(
argv
);
// clear misc
(
void
)
UpdateMiscMessage
(
NULL
,
"reboot"
,
NULL
,
NULL
);
return
DoRoot_
(
"reboot"
,
RB_POWER_OFF
);
...
...
@@ -53,6 +57,7 @@ static int DoRebootShutdown(int id, const char *name, int argc, const char **arg
static
int
DoRebootUpdater
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
PLUGIN_LOGI
(
"DoRebootUpdater argc %d %s"
,
argc
,
name
);
PLUGIN_CHECK
(
argc
>=
1
,
return
-
1
,
"Invalid parameter"
);
PLUGIN_LOGI
(
"DoRebootUpdater argv %s"
,
argv
[
0
]);
...
...
@@ -65,6 +70,7 @@ static int DoRebootUpdater(int id, const char *name, int argc, const char **argv
static
int
DoRebootFlashed
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
PLUGIN_LOGI
(
"DoRebootFlashed argc %d %s"
,
argc
,
name
);
PLUGIN_CHECK
(
argc
>=
1
,
return
-
1
,
"Invalid parameter"
);
PLUGIN_LOGI
(
"DoRebootFlashd argv %s"
,
argv
[
0
]);
...
...
@@ -77,6 +83,10 @@ static int DoRebootFlashed(int id, const char *name, int argc, const char **argv
static
int
DoRebootCharge
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
UNUSED
(
name
);
UNUSED
(
argc
);
UNUSED
(
argv
);
int
ret
=
UpdateMiscMessage
(
NULL
,
"charge"
,
"charge:"
,
"boot_charge"
);
if
(
ret
==
0
)
{
return
DoRoot_
(
"reboot"
,
RB_AUTOBOOT
);
...
...
@@ -84,46 +94,25 @@ static int DoRebootCharge(int id, const char *name, int argc, const char **argv)
return
ret
;
}
#ifdef PRODUCT_RK
#include <sys/syscall.h>
#define REBOOT_MAGIC1 0xfee1dead
#define REBOOT_MAGIC2 672274793
#define REBOOT_CMD_RESTART2 0xA1B2C3D4
static
int
DoRebootLoader
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
static
int
DoRebootSuspend
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
// by job to stop service and unmount
DoJobNow
(
"reboot"
);
syscall
(
__NR_reboot
,
REBOOT_MAGIC1
,
REBOOT_MAGIC2
,
REBOOT_CMD_RESTART2
,
"loader"
);
return
0
;
UNUSED
(
id
);
UNUSED
(
name
);
UNUSED
(
argc
);
UNUSED
(
argv
);
return
DoRoot_
(
"suspend"
,
RB_AUTOBOOT
);
}
#endif
static
ModuleCmdInfo
g_rebootCmdIds
[]
=
{
{
"reboot.shutdown"
,
DoRebootShutdown
,
0
},
{
"reboot.flashd"
,
DoRebootFlashed
,
0
},
{
"reboot.updater"
,
DoRebootUpdater
,
0
},
{
"reboot.charge"
,
DoRebootCharge
,
0
},
#ifdef PRODUCT_RK
{
"reboot.loader"
,
DoRebootLoader
,
0
},
#endif
{
"reboot"
,
DoReboot
,
0
},
};
static
void
RebootAdpInit
(
void
)
{
for
(
size_t
i
=
0
;
i
<
sizeof
(
g_rebootCmdIds
)
/
sizeof
(
g_rebootCmdIds
[
0
]);
i
++
)
{
g_rebootCmdIds
[
i
].
cmdId
=
(
uint32_t
)
AddCmdExecutor
(
g_rebootCmdIds
[
i
].
cmd
,
g_rebootCmdIds
[
i
].
executor
);
}
}
static
void
RebootAdpExit
(
void
)
{
for
(
size_t
i
=
0
;
i
<
sizeof
(
g_rebootCmdIds
)
/
sizeof
(
g_rebootCmdIds
[
0
]);
i
++
)
{
if
(
g_rebootCmdIds
[
i
].
cmdId
==
0
)
{
continue
;
}
RemoveCmdExecutor
(
g_rebootCmdIds
[
i
].
cmd
,
g_rebootCmdIds
[
i
].
cmdId
);
}
// sample {"reboot,shutdown", "reboot.shutdown", "reboot.shutdown"},
// add default reboot cmd
(
void
)
AddCmdExecutor
(
"reboot"
,
DoReboot
);
AddRebootCmdExecutor
(
"shutdown"
,
DoRebootShutdown
);
AddRebootCmdExecutor
(
"flashd"
,
DoRebootFlashed
);
AddRebootCmdExecutor
(
"updater"
,
DoRebootUpdater
);
AddRebootCmdExecutor
(
"charge"
,
DoRebootCharge
);
AddRebootCmdExecutor
(
"suspend"
,
DoRebootSuspend
);
}
MODULE_CONSTRUCTOR
(
void
)
...
...
@@ -135,5 +124,4 @@ MODULE_CONSTRUCTOR(void)
MODULE_DESTRUCTOR
(
void
)
{
PLUGIN_LOGI
(
"Reboot adapter plug-in exit now ..."
);
RebootAdpExit
();
}
services/modules/reboot/reboot_static.c
浏览文件 @
cde18501
...
...
@@ -12,11 +12,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include "bootstage.h"
#include "hookmgr.h"
#include "init_hook.h"
#include "init_module_engine.h"
#include "plugin_adapter.h"
#include "hookmgr.h"
#include "bootstage.h"
#include "securec.h"
#define REBOOT_NAME_PREFIX "reboot,"
#define REBOOT_CMD_PREFIX "reboot."
#define REBOOT_REPLACE_PREFIX "reboot."
static
int
RebootHookWrapper
(
const
HOOK_INFO
*
hookInfo
,
void
*
executionContext
)
{
...
...
@@ -36,13 +43,113 @@ int InitAddRebootHook(InitRebootHook hook)
return
HookMgrAddEx
(
GetBootStageHookMgr
(),
&
info
);
}
static
int
RebookGlobalHook
(
const
HOOK_INFO
*
hookInfo
,
void
*
cookie
)
static
ParamCmdInfo
*
g_rebootParamCmdInfos
=
NULL
;
static
int
g_rebootParamCmdMaxNumber
=
0
;
static
int
g_rebootParamCmdValidNumber
=
0
;
static
char
*
Dup2String
(
const
char
*
prefix
,
const
char
*
str
)
{
InitModuleMgrInstall
(
"rebootmodule"
);
PLUGIN_LOGI
(
"Install rebootmodule."
);
if
(
str
==
NULL
)
{
return
strdup
(
"reboot"
);
}
size_t
len
=
strlen
(
prefix
)
+
strlen
(
str
)
+
1
;
char
*
tmp
=
calloc
(
1
,
len
);
PLUGIN_CHECK
(
tmp
!=
NULL
,
return
NULL
,
"Failed to alloc %s %s"
,
prefix
,
str
);
int
ret
=
sprintf_s
(
tmp
,
len
,
"%s%s"
,
prefix
,
str
);
PLUGIN_CHECK
(
ret
>
0
,
free
(
tmp
);
return
NULL
,
"Failed to sprintf %s %s"
,
prefix
,
str
);
return
tmp
;
}
static
int
CheckParamCmdExist
(
const
char
*
cmd
)
{
if
(
g_rebootParamCmdInfos
==
NULL
)
{
return
0
;
}
char
*
cmdName
=
Dup2String
(
REBOOT_CMD_PREFIX
,
cmd
);
PLUGIN_CHECK
(
cmdName
!=
NULL
,
return
0
,
"Failed to copy %s"
,
cmd
);
for
(
int
i
=
0
;
i
<
g_rebootParamCmdValidNumber
;
i
++
)
{
if
(
strcmp
(
g_rebootParamCmdInfos
[
i
].
cmd
,
cmdName
)
==
0
)
{
free
(
cmdName
);
return
1
;
}
}
free
(
cmdName
);
return
0
;
}
static
int
SetParamCmdInfo
(
ParamCmdInfo
*
currInfo
,
CmdExecutor
executor
,
const
char
*
cmd
)
{
do
{
currInfo
->
name
=
Dup2String
(
REBOOT_NAME_PREFIX
,
cmd
);
PLUGIN_CHECK
(
currInfo
->
name
!=
NULL
,
break
,
"Failed to copy %s"
,
cmd
);
currInfo
->
replace
=
Dup2String
(
REBOOT_REPLACE_PREFIX
,
cmd
);
PLUGIN_CHECK
(
currInfo
->
replace
!=
NULL
,
break
,
"Failed to copy %s"
,
cmd
);
currInfo
->
cmd
=
Dup2String
(
REBOOT_CMD_PREFIX
,
cmd
);
PLUGIN_CHECK
(
currInfo
->
cmd
!=
NULL
,
break
,
"Failed to copy %s"
,
cmd
);
if
(
executor
!=
NULL
)
{
int
cmdId
=
AddCmdExecutor
(
currInfo
->
cmd
,
executor
);
PLUGIN_CHECK
(
cmdId
>
0
,
break
,
"Failed to add cmd %s"
,
cmd
);
}
PLUGIN_LOGV
(
"SetParamCmdInfo '%s' '%s' '%s' "
,
currInfo
->
name
,
currInfo
->
cmd
,
currInfo
->
replace
);
currInfo
=
NULL
;
g_rebootParamCmdValidNumber
++
;
return
0
;
}
while
(
0
);
if
(
currInfo
!=
NULL
)
{
if
(
currInfo
->
name
!=
NULL
)
{
free
(
currInfo
->
name
);
}
if
(
currInfo
->
cmd
!=
NULL
)
{
free
(
currInfo
->
cmd
);
}
if
(
currInfo
->
replace
!=
NULL
)
{
free
(
currInfo
->
replace
);
}
}
return
-
1
;
}
static
int
AddRebootCmdExecutor_
(
const
char
*
cmd
,
CmdExecutor
executor
)
{
if
(
g_rebootParamCmdMaxNumber
==
0
||
g_rebootParamCmdMaxNumber
<=
g_rebootParamCmdValidNumber
)
{
g_rebootParamCmdMaxNumber
+=
5
;
// inc 5 once time
ParamCmdInfo
*
cmdInfos
=
calloc
(
1
,
sizeof
(
ParamCmdInfo
)
*
g_rebootParamCmdMaxNumber
);
PLUGIN_CHECK
(
cmdInfos
!=
NULL
,
return
-
1
,
"Failed to add reboot cmd %s"
,
cmd
);
if
(
g_rebootParamCmdInfos
!=
NULL
)
{
// delete old
// copy from old
for
(
int
i
=
0
;
i
<
g_rebootParamCmdValidNumber
;
i
++
)
{
cmdInfos
[
i
].
name
=
g_rebootParamCmdInfos
[
i
].
name
;
cmdInfos
[
i
].
replace
=
g_rebootParamCmdInfos
[
i
].
replace
;
cmdInfos
[
i
].
cmd
=
g_rebootParamCmdInfos
[
i
].
cmd
;
}
free
(
g_rebootParamCmdInfos
);
}
g_rebootParamCmdInfos
=
cmdInfos
;
}
return
SetParamCmdInfo
(
&
g_rebootParamCmdInfos
[
g_rebootParamCmdValidNumber
],
executor
,
cmd
);
}
int
AddRebootCmdExecutor
(
const
char
*
cmd
,
CmdExecutor
executor
)
{
PLUGIN_CHECK
(
cmd
!=
NULL
&&
executor
!=
NULL
,
return
EINVAL
,
"Invalid input parameter"
);
int
ret
=
CheckParamCmdExist
(
cmd
);
if
(
ret
!=
0
)
{
PLUGIN_LOGI
(
"Cmd %s exist"
,
cmd
);
return
EEXIST
;
}
return
AddRebootCmdExecutor_
(
cmd
,
executor
);
}
const
ParamCmdInfo
*
GetStartupPowerCtl
(
size_t
*
size
)
{
RebootHookCtx
context
;
context
.
reason
=
""
;
(
void
)
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_REBOOT
,
(
void
*
)(
&
context
),
NULL
);
PLUGIN_LOGI
(
"After install reboot module"
);
*
size
=
g_rebootParamCmdValidNumber
;
return
g_rebootParamCmdInfos
;
}
static
void
InitRebootHook_
(
RebootHookCtx
*
ctx
)
{
InitModuleMgrInstall
(
"rebootmodule"
);
...
...
@@ -53,5 +160,4 @@ MODULE_CONSTRUCTOR(void)
{
// 执行reboot时调用,安装reboot模块
InitAddRebootHook
(
InitRebootHook_
);
InitAddGlobalInitHook
(
0
,
RebookGlobalHook
);
}
\ No newline at end of file
}
services/param/linux/param_service.c
浏览文件 @
cde18501
...
...
@@ -95,7 +95,7 @@ static int SendResponseMsg(ParamTaskPtr worker, const ParamMessage *msg, int res
response
->
result
=
result
;
response
->
msg
.
msgSize
=
sizeof
(
ParamResponseMessage
);
ParamTaskSendMsg
(
worker
,
(
ParamMessage
*
)
response
);
PARAM_LOG
I
(
"Send response msg msgId %d result %d"
,
msg
->
id
.
msgId
,
result
);
PARAM_LOG
V
(
"Send response msg msgId %d result %d"
,
msg
->
id
.
msgId
,
result
);
return
0
;
}
...
...
services/param/manager/param_manager.c
浏览文件 @
cde18501
...
...
@@ -279,24 +279,40 @@ static int CreateCtrlInfo(ServiceCtrlInfo **ctrlInfo, const char *cmd, uint32_t
return
0
;
}
static
int
GetServiceCtrlInfoForPowerCtrl
(
const
char
*
name
,
const
char
*
value
,
ServiceCtrlInfo
**
ctrlInfo
)
{
size_t
size
=
0
;
const
ParamCmdInfo
*
powerCtrlArg
=
GetStartupPowerCtl
(
&
size
);
PARAM_CHECK
(
powerCtrlArg
!=
NULL
,
return
-
1
,
"Invalid ctrlInfo for %s"
,
name
);
uint32_t
valueOffset
=
strlen
(
OHOS_SERVICE_CTRL_PREFIX
)
+
strlen
(
"reboot"
)
+
1
;
if
(
strcmp
(
value
,
"reboot"
)
==
0
)
{
return
CreateCtrlInfo
(
ctrlInfo
,
"reboot"
,
valueOffset
,
1
,
"%s%s.%s"
,
OHOS_SERVICE_CTRL_PREFIX
,
"reboot"
,
value
);
}
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
{
PARAM_LOGV
(
"Get power ctrl %s name %s value %s"
,
powerCtrlArg
[
i
].
name
,
name
,
value
);
if
(
strncmp
(
value
,
powerCtrlArg
[
i
].
name
,
strlen
(
powerCtrlArg
[
i
].
name
))
==
0
)
{
valueOffset
=
strlen
(
OHOS_SERVICE_CTRL_PREFIX
)
+
strlen
(
powerCtrlArg
[
i
].
replace
)
+
1
;
return
CreateCtrlInfo
(
ctrlInfo
,
powerCtrlArg
[
i
].
cmd
,
valueOffset
,
1
,
"%s%s.%s"
,
OHOS_SERVICE_CTRL_PREFIX
,
powerCtrlArg
[
i
].
replace
,
value
);
}
}
// not found reboot, so reboot by normal
valueOffset
=
strlen
(
OHOS_SERVICE_CTRL_PREFIX
)
+
strlen
(
"reboot"
)
+
1
;
return
CreateCtrlInfo
(
ctrlInfo
,
"reboot"
,
valueOffset
,
1
,
"%s%s.%s"
,
OHOS_SERVICE_CTRL_PREFIX
,
"reboot"
,
value
);
}
INIT_LOCAL_API
int
GetServiceCtrlInfo
(
const
char
*
name
,
const
char
*
value
,
ServiceCtrlInfo
**
ctrlInfo
)
{
PARAM_CHECK
(
ctrlInfo
!=
NULL
,
return
-
1
,
"Invalid ctrlInfo %s"
,
name
);
*
ctrlInfo
=
NULL
;
size_t
size
=
0
;
if
(
strcmp
(
"ohos.startup.powerctrl"
,
name
)
==
0
)
{
const
ParamCmdInfo
*
powerCtrlArg
=
GetStartupPowerCtl
(
&
size
);
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
{
if
(
strncmp
(
value
,
powerCtrlArg
[
i
].
name
,
strlen
(
powerCtrlArg
[
i
].
name
))
==
0
)
{
uint32_t
valueOffset
=
strlen
(
OHOS_SERVICE_CTRL_PREFIX
)
+
strlen
(
powerCtrlArg
[
i
].
replace
)
+
1
;
return
CreateCtrlInfo
(
ctrlInfo
,
powerCtrlArg
[
i
].
cmd
,
valueOffset
,
1
,
"%s%s.%s"
,
OHOS_SERVICE_CTRL_PREFIX
,
powerCtrlArg
[
i
].
replace
,
value
);
}
}
return
0
;
return
GetServiceCtrlInfoForPowerCtrl
(
name
,
value
,
ctrlInfo
);
}
if
(
strncmp
(
"ohos.ctl."
,
name
,
strlen
(
"ohos.ctl."
))
==
0
)
{
const
ParamCmdInfo
*
ctrlParam
=
GetServiceStartCtrl
(
&
size
);
PARAM_CHECK
(
ctrlParam
!=
NULL
,
return
-
1
,
"Invalid ctrlInfo for %s"
,
name
);
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
{
if
(
strcmp
(
name
,
ctrlParam
[
i
].
name
)
==
0
)
{
uint32_t
valueOffset
=
strlen
(
OHOS_SERVICE_CTRL_PREFIX
)
+
strlen
(
ctrlParam
[
i
].
replace
)
+
1
;
...
...
@@ -307,6 +323,7 @@ INIT_LOCAL_API int GetServiceCtrlInfo(const char *name, const char *value, Servi
}
if
(
strncmp
(
"ohos.servicectrl."
,
name
,
strlen
(
"ohos.servicectrl."
))
==
0
)
{
const
ParamCmdInfo
*
installParam
=
GetServiceCtl
(
&
size
);
PARAM_CHECK
(
installParam
!=
NULL
,
return
-
1
,
"Invalid ctrlInfo for %s"
,
name
);
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
{
if
(
strncmp
(
name
,
installParam
[
i
].
name
,
strlen
(
installParam
[
i
].
name
))
==
0
)
{
return
CreateCtrlInfo
(
ctrlInfo
,
installParam
[
i
].
cmd
,
strlen
(
name
)
+
1
,
1
,
"%s.%s"
,
name
,
value
);
...
...
services/param/trigger/trigger_checker.c
浏览文件 @
cde18501
...
...
@@ -328,8 +328,20 @@ int CheckMatchSubCondition(const char *condition, const char *input, int length)
{
PARAM_CHECK
(
condition
!=
NULL
,
return
0
,
"Invalid condition"
);
PARAM_CHECK
(
input
!=
NULL
,
return
0
,
"Invalid input"
);
char
*
tmp
=
strstr
(
condition
,
input
);
if
((
tmp
!=
NULL
)
&&
((
int
)
strlen
(
tmp
)
>
length
)
&&
(
tmp
[
length
]
==
'='
))
{
const
char
*
tmp
=
strstr
(
condition
,
input
);
if
(
tmp
==
NULL
)
{
return
0
;
}
PARAM_LOGV
(
"CheckMatchSubCondition Condition: '%s' content: '%s' length %d"
,
condition
,
input
,
length
);
if
(((
int
)
strlen
(
tmp
)
<=
length
)
||
(
tmp
[
length
]
!=
'='
))
{
return
0
;
}
// for condition: parameter = 1
if
(
tmp
==
condition
)
{
return
1
;
}
// for condition: parameter1 = 1 && parameter2 = 1
if
(
*
(
tmp
-
1
)
==
' '
)
{
return
1
;
}
return
0
;
...
...
services/param/trigger/trigger_manager.c
浏览文件 @
cde18501
...
...
@@ -448,8 +448,7 @@ int32_t CheckAndMarkTrigger_(const TriggerWorkSpace *workSpace, int type, const
trigger
=
head
->
nextTrigger
(
head
,
trigger
);
continue
;
}
const
char
*
tmp
=
strstr
(
head
->
getCondition
(
trigger
),
name
);
if
(
tmp
!=
NULL
&&
strncmp
(
tmp
+
strlen
(
name
),
"="
,
1
)
==
0
)
{
if
(
CheckMatchSubCondition
(
head
->
getCondition
(
trigger
),
name
,
strlen
(
name
))
==
1
)
{
TRIGGER_SET_FLAG
(
trigger
,
TRIGGER_FLAGS_RELATED
);
ret
=
1
;
}
...
...
test/moduletest/param_test_cmds.c
浏览文件 @
cde18501
...
...
@@ -100,7 +100,7 @@ static void HandleParamChange2(const char *key, const char *value, void *context
index
=
5
;
// 5 add context
ret
=
SystemWatchParameter
(
key
,
HandleParamChange2
,
(
void
*
)
index
);
if
(
ret
!=
0
)
{
printf
(
"Add watcher %s fail %
d
\n
"
,
key
,
index
);
printf
(
"Add watcher %s fail %
zu
\n
"
,
key
,
index
);
}
addWatcher
=
1
;
return
;
...
...
@@ -109,21 +109,21 @@ static void HandleParamChange2(const char *key, const char *value, void *context
index
=
3
;
// 3 delete context
RemoveParameterWatcher
(
key
,
HandleParamChange2
,
(
void
*
)
index
);
if
(
ret
!=
0
)
{
printf
(
"Remove watcher fail %
d
\n
"
,
index
);
printf
(
"Remove watcher fail %
zu
\n
"
,
index
);
}
return
;
}
if
(
index
==
1
)
{
// 1 when context == 1 delete 1
RemoveParameterWatcher
(
key
,
HandleParamChange2
,
(
void
*
)
index
);
if
(
ret
!=
0
)
{
printf
(
"Remove watcher fail %
d
\n
"
,
index
);
printf
(
"Remove watcher fail %
zu
\n
"
,
index
);
}
return
;
}
if
((
index
==
5
)
&&
(
addWatcher
==
1
))
{
// 5 when context == 5 delete 5
RemoveParameterWatcher
(
key
,
HandleParamChange2
,
(
void
*
)
index
);
if
(
ret
!=
0
)
{
printf
(
"Remove watcher fail %
d
\n
"
,
index
);
printf
(
"Remove watcher fail %
zu
\n
"
,
index
);
}
addWatcher
=
0
;
}
...
...
@@ -143,18 +143,18 @@ static void *CmdThreadWatcher(void *args)
for
(
size_t
i
=
1
;
i
<=
MAX_NUMBER
;
i
++
)
{
int
ret
=
SystemWatchParameter
(
context
->
name
,
HandleParamChange2
,
(
void
*
)
i
);
if
(
ret
!=
0
)
{
printf
(
"Add watcher %s fail %
d
\n
"
,
context
->
name
,
i
);
printf
(
"Add watcher %s fail %
zu
\n
"
,
context
->
name
,
i
);
}
ret
=
SetParameter
(
context
->
name
,
context
->
name
);
if
(
ret
!=
0
)
{
printf
(
"Set parameter %s fail %
d
\n
"
,
context
->
name
,
i
);
printf
(
"Set parameter %s fail %
zu
\n
"
,
context
->
name
,
i
);
}
}
sleep
(
1
);
for
(
size_t
i
=
1
;
i
<=
MAX_NUMBER
;
i
++
)
{
int
ret
=
RemoveParameterWatcher
(
context
->
name
,
HandleParamChange2
,
(
void
*
)
i
);
if
(
ret
!=
0
)
{
printf
(
"Remove watcher %s fail %
d
\n
"
,
context
->
name
,
i
);
printf
(
"Remove watcher %s fail %
zu
\n
"
,
context
->
name
,
i
);
}
}
free
(
context
);
...
...
test/unittest/BUILD.gn
浏览文件 @
cde18501
...
...
@@ -81,7 +81,9 @@ ohos_unittest("init_unittest") {
"//base/startup/init/services/modules/bootevent/bootevent.c",
"//base/startup/init/services/modules/init_hook/init_hook.c",
"//base/startup/init/services/modules/init_hook/param_hook.c",
"//base/startup/init/services/modules/reboot/reboot.c",
"//base/startup/init/services/modules/reboot/reboot_misc.c",
"//base/startup/init/services/modules/reboot/reboot_static.c",
"//base/startup/init/services/param/adapter/param_dac.c",
"//base/startup/init/services/param/adapter/param_persistadp.c",
"//base/startup/init/services/param/base/param_base.c",
...
...
test/unittest/init/init_reboot_unittest.cpp
浏览文件 @
cde18501
...
...
@@ -21,6 +21,7 @@
#include "init_utils.h"
#include "trigger_manager.h"
#include "init_group_manager.h"
#include "init_cmdexecutor.h"
using
namespace
testing
::
ext
;
using
namespace
std
;
...
...
@@ -34,6 +35,59 @@ public:
void
TearDown
()
{};
};
#ifndef OHOS_LITE
static
int
g_result
=
0
;
HWTEST_F
(
InitRebootUnitTest
,
TestAddRebootCmd
,
TestSize
.
Level1
)
{
auto
rebootCallback
=
[](
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
->
int
{
return
0
;
};
int
ret
=
AddRebootCmdExecutor
(
"reboot_cmd1"
,
rebootCallback
);
EXPECT_EQ
(
ret
,
0
);
ret
=
AddRebootCmdExecutor
(
"reboot_cmd2"
,
rebootCallback
);
EXPECT_EQ
(
ret
,
0
);
ret
=
AddRebootCmdExecutor
(
"reboot_cmd3"
,
rebootCallback
);
EXPECT_EQ
(
ret
,
0
);
ret
=
AddRebootCmdExecutor
(
"reboot_cmd4"
,
[](
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
->
int
{
g_result
=
4
;
// 4 test index
return
0
;
});
EXPECT_EQ
(
ret
,
0
);
ret
=
AddRebootCmdExecutor
(
"reboot_cmd5"
,
[](
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
->
int
{
g_result
=
5
;
// 5 test index
return
0
;
});
EXPECT_EQ
(
ret
,
0
);
ret
=
AddRebootCmdExecutor
(
"reboot_cmd6"
,
[](
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
->
int
{
g_result
=
6
;
// 6 test index
return
0
;
});
EXPECT_EQ
(
ret
,
0
);
ret
=
AddRebootCmdExecutor
(
"reboot_cmd7"
,
rebootCallback
);
EXPECT_EQ
(
ret
,
0
);
ret
=
AddRebootCmdExecutor
(
"reboot_cmd7"
,
rebootCallback
);
EXPECT_NE
(
ret
,
0
);
TestSetParamCheckResult
(
"ohos.servicectrl.reboot"
,
0777
,
0
);
// exec
SystemWriteParam
(
"ohos.startup.powerctrl"
,
"reboot,reboot_cmd4"
);
EXPECT_EQ
(
g_result
,
4
);
// 4 test index
SystemWriteParam
(
"ohos.startup.powerctrl"
,
"reboot,reboot_cmd5"
);
EXPECT_EQ
(
g_result
,
5
);
// 5 test index
SystemWriteParam
(
"ohos.startup.powerctrl"
,
"reboot,reboot_cmd6"
);
EXPECT_EQ
(
g_result
,
6
);
// 6 test index
// invalid test
ret
=
AddRebootCmdExecutor
(
nullptr
,
[](
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
->
int
{
printf
(
"reboot_cmd7 %s"
,
name
);
return
0
;
});
EXPECT_NE
(
ret
,
0
);
ret
=
AddRebootCmdExecutor
(
nullptr
,
nullptr
);
EXPECT_NE
(
ret
,
0
);
}
#endif
HWTEST_F
(
InitRebootUnitTest
,
TestInitReboot
,
TestSize
.
Level1
)
{
ExecReboot
(
"reboot"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录