Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
1b4a5685
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看板
提交
1b4a5685
编写于
5月 19, 2023
作者:
C
cheng_jinsong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add shutdown option
Signed-off-by:
N
cheng_jinsong
<
chengjinsong2@huawei.com
>
上级
eb438eb7
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
216 addition
and
23 deletion
+216
-23
interfaces/innerkits/include/init_reboot.h
interfaces/innerkits/include/init_reboot.h
+18
-0
interfaces/innerkits/libbegetutil.versionscript
interfaces/innerkits/libbegetutil.versionscript
+1
-0
interfaces/innerkits/reboot/init_reboot_innerkits.c
interfaces/innerkits/reboot/init_reboot_innerkits.c
+28
-16
services/begetctl/init_cmd_reboot.c
services/begetctl/init_cmd_reboot.c
+1
-1
services/modules/reboot/reboot.c
services/modules/reboot/reboot.c
+18
-0
services/modules/selinux/selinux_adp.c
services/modules/selinux/selinux_adp.c
+3
-0
test/fuzztest/BUILD.gn
test/fuzztest/BUILD.gn
+24
-0
test/fuzztest/DoRebootExt_fuzzer/DoRebootExt_fuzzer.cpp
test/fuzztest/DoRebootExt_fuzzer/DoRebootExt_fuzzer.cpp
+38
-0
test/fuzztest/DoRebootExt_fuzzer/DoRebootExt_fuzzer.h
test/fuzztest/DoRebootExt_fuzzer/DoRebootExt_fuzzer.h
+20
-0
test/fuzztest/DoRebootExt_fuzzer/corpus/init
test/fuzztest/DoRebootExt_fuzzer/corpus/init
+16
-0
test/fuzztest/DoRebootExt_fuzzer/project.xml
test/fuzztest/DoRebootExt_fuzzer/project.xml
+25
-0
test/unittest/init/init_reboot_unittest.cpp
test/unittest/init/init_reboot_unittest.cpp
+24
-6
未找到文件。
interfaces/innerkits/include/init_reboot.h
浏览文件 @
1b4a5685
...
...
@@ -29,8 +29,26 @@ extern "C" {
#define DEVICE_CMD_FREEZE "freeze"
#define DEVICE_CMD_RESTORE "restore"
/**
* @brief reboot system
*
* @param option format is: mode[:info]
* mode : command sub key, example: updater, shutdown ...
* info : extend info
* @return int
*/
int
DoReboot
(
const
char
*
cmdContent
);
/**
* @brief reboot system
*
* @param mode command sub key, example: updater, shutdown ...
* @param option extend info
*
* @return int
*/
int
DoRebootExt
(
const
char
*
mode
,
const
char
*
option
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
interfaces/innerkits/libbegetutil.versionscript
浏览文件 @
1b4a5685
...
...
@@ -48,6 +48,7 @@
CachedParameterGetChanged;
CachedParameterDestroy;
DoReboot;
DoRebootExt;
GetControlSocket;
OH_ListAddTail;
OH_ListAddWithOrder;
...
...
interfaces/innerkits/reboot/init_reboot_innerkits.c
浏览文件 @
1b4a5685
...
...
@@ -30,23 +30,25 @@
#define DOREBOOT_PARAM "reboot.ut"
#endif
static
int
DoReboot_
(
const
char
*
option
)
static
int
DoReboot_
(
const
char
*
mode
,
const
char
*
option
)
{
char
value
[
MAX_REBOOT_OPTION_SIZE
];
int
ret
=
0
;
if
(
option
==
NULL
||
strlen
(
option
)
==
0
)
{
ret
=
SystemSetParameter
(
STARTUP_DEVICE_CTL
,
DEVICE_CMD_STOP
);
BEGET_ERROR_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to set stop param"
);
ret
=
SystemSetParameter
(
DOREBOOT_PARAM
,
"reboot"
);
BEGET_ERROR_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to set reboot param"
);
return
0
;
if
(
mode
!=
NULL
)
{
if
((
option
!=
NULL
)
&&
(
strlen
(
option
)
>=
0
))
{
ret
=
snprintf_s
(
value
,
MAX_REBOOT_OPTION_SIZE
,
MAX_REBOOT_OPTION_SIZE
-
1
,
"reboot,%s:%s"
,
mode
,
option
);
}
else
{
ret
=
snprintf_s
(
value
,
MAX_REBOOT_OPTION_SIZE
,
MAX_REBOOT_OPTION_SIZE
-
1
,
"reboot,%s"
,
mode
);
}
}
else
{
if
((
option
!=
NULL
)
&&
(
strlen
(
option
)
>=
0
))
{
ret
=
snprintf_s
(
value
,
MAX_REBOOT_OPTION_SIZE
,
MAX_REBOOT_OPTION_SIZE
-
1
,
"reboot,%s"
,
option
);
}
else
{
ret
=
snprintf_s
(
value
,
MAX_REBOOT_OPTION_SIZE
,
MAX_REBOOT_OPTION_SIZE
-
1
,
"%s"
,
"reboot"
);
}
}
int
length
=
strlen
(
option
);
BEGET_ERROR_CHECK
(
length
<=
MAX_REBOOT_OPTION_SIZE
,
return
-
1
,
"Reboot option
\"
%s
\"
is too large, overflow"
,
option
);
ret
=
snprintf_s
(
value
,
MAX_REBOOT_OPTION_SIZE
,
MAX_REBOOT_OPTION_SIZE
-
1
,
"reboot,%s"
,
option
);
BEGET_ERROR_CHECK
(
ret
>=
0
,
return
-
1
,
"Failed to copy boot option
\"
%s
\"
"
,
option
);
BEGET_ERROR_CHECK
(
ret
>=
0
,
return
-
1
,
"Failed to format boot mode "
);
BEGET_LOGV
(
"Reboot cmd %s"
,
value
);
ret
=
SystemSetParameter
(
STARTUP_DEVICE_CTL
,
DEVICE_CMD_STOP
);
BEGET_ERROR_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to set stop param"
);
ret
=
SystemSetParameter
(
DOREBOOT_PARAM
,
value
);
...
...
@@ -54,7 +56,7 @@ static int DoReboot_(const char *option)
return
0
;
}
int
DoReboot
(
const
char
*
option
)
static
int
ExecReboot_
(
const
char
*
mode
,
const
char
*
option
)
{
// check if param set ok
#ifndef STARTUP_INIT_TEST
...
...
@@ -63,7 +65,7 @@ int DoReboot(const char *option)
const
int
maxCount
=
1
;
#endif
int
count
=
0
;
DoReboot_
(
option
);
DoReboot_
(
mode
,
option
);
while
(
count
<
maxCount
)
{
usleep
(
100
*
1000
);
// 100 * 1000 wait 100ms
char
result
[
10
]
=
{
0
};
// 10 stop len
...
...
@@ -74,8 +76,18 @@ int DoReboot(const char *option)
return
0
;
}
count
++
;
DoReboot_
(
option
);
DoReboot_
(
mode
,
option
);
}
BEGET_LOGE
(
"Failed to reboot system"
);
return
0
;
}
int
DoReboot
(
const
char
*
option
)
{
return
ExecReboot_
(
NULL
,
option
);
}
int
DoRebootExt
(
const
char
*
mode
,
const
char
*
option
)
{
return
ExecReboot_
(
mode
,
option
);
}
\ No newline at end of file
services/begetctl/init_cmd_reboot.c
浏览文件 @
1b4a5685
...
...
@@ -49,7 +49,7 @@ MODULE_CONSTRUCTOR(void)
{
CmdInfo
infos
[]
=
{
{
"reboot"
,
main_cmd
,
"reboot system"
,
"reboot"
,
""
},
{
"reboot"
,
main_cmd
,
"shutdown system"
,
"reboot shutdown"
,
""
},
{
"reboot"
,
main_cmd
,
"shutdown system"
,
"reboot shutdown
[:options]
"
,
""
},
{
"reboot"
,
main_cmd
,
"suspend system"
,
"reboot suspend"
,
""
},
{
"reboot"
,
main_cmd
,
"reboot and boot into updater"
,
"reboot updater"
,
""
},
{
"reboot"
,
main_cmd
,
"reboot and boot into updater"
,
"reboot updater[:options]"
,
""
},
...
...
services/modules/reboot/reboot.c
浏览文件 @
1b4a5685
...
...
@@ -78,8 +78,22 @@ static int DoRebootShutdown(int id, const char *name, int argc, const char **arg
UNUSED
(
name
);
UNUSED
(
argc
);
UNUSED
(
argv
);
PLUGIN_CHECK
(
argc
>=
1
,
return
-
1
,
"Invalid parameter"
);
// clear misc
(
void
)
UpdateMiscMessage
(
NULL
,
"reboot"
,
NULL
,
NULL
);
const
size_t
len
=
strlen
(
"reboot,"
);
const
char
*
cmd
=
strstr
(
argv
[
0
],
"reboot,"
);
if
(
cmd
!=
NULL
&&
strlen
(
cmd
)
>
len
)
{
PLUGIN_LOGI
(
"DoRebootShutdown argv %s"
,
cmd
+
len
);
// by job to stop service and unmount
DoJobNow
(
"reboot"
);
#ifndef STARTUP_INIT_TEST
return
syscall
(
__NR_reboot
,
LINUX_REBOOT_MAGIC1
,
LINUX_REBOOT_MAGIC2
,
LINUX_REBOOT_CMD_POWER_OFF
,
cmd
+
len
);
#else
return
0
;
#endif
}
return
DoRoot_
(
"reboot"
,
RB_POWER_OFF
);
}
...
...
@@ -139,8 +153,12 @@ static int DoRebootOther(int id, const char *name, int argc, const char **argv)
const
char
*
cmd
=
strstr
(
argv
[
0
],
"reboot,"
);
PLUGIN_CHECK
(
cmd
!=
NULL
,
return
-
1
,
"Invalid parameter argc %s"
,
argv
[
0
]);
PLUGIN_LOGI
(
"DoRebootOther argv %s"
,
argv
[
0
]);
#ifndef STARTUP_INIT_TEST
return
syscall
(
__NR_reboot
,
LINUX_REBOOT_MAGIC1
,
LINUX_REBOOT_MAGIC2
,
LINUX_REBOOT_CMD_RESTART2
,
cmd
+
strlen
(
"reboot,"
));
#else
return
0
;
#endif
}
static
void
RebootAdpInit
(
void
)
...
...
services/modules/selinux/selinux_adp.c
浏览文件 @
1b4a5685
...
...
@@ -145,6 +145,9 @@ MODULE_CONSTRUCTOR(void)
MODULE_DESTRUCTOR
(
void
)
{
if
(
getpid
()
!=
1
)
{
return
;
}
PLUGIN_LOGI
(
"Selinux adapter plug-in exit now ..."
);
SelinuxAdpExit
();
}
test/fuzztest/BUILD.gn
浏览文件 @
1b4a5685
...
...
@@ -52,6 +52,30 @@ ohos_fuzztest("DoRebootFuzzTest") {
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("DoRebootExtFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//base/startup/init/test/fuzztest/DoRebootExt_fuzzer"
include_dirs = [
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/test/fuzztest/utils/include",
]
deps = [
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//third_party/bounds_checking_function:libsec_static",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "DoRebootExt_fuzzer/DoRebootExt_fuzzer.cpp" ]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("GetControlFileFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//base/startup/init/test/fuzztest/getcontrolfile_fuzzer"
...
...
test/fuzztest/DoRebootExt_fuzzer/DoRebootExt_fuzzer.cpp
0 → 100755
浏览文件 @
1b4a5685
/*
* Copyright (c) 2023 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 "DoRebootExt_fuzzer.h"
#include<string>
#include "init_reboot.h"
namespace
OHOS
{
bool
FuzzDoRebootExt
(
const
uint8_t
*
data
,
size_t
size
)
{
bool
result
=
false
;
std
::
string
str
(
reinterpret_cast
<
const
char
*>
(
data
),
size
);
if
(
!
DoRebootExt
(
str
.
c_str
(),
str
.
c_str
()))
{
result
=
true
;
}
return
result
;
}
}
/* Fuzzer entry point */
extern
"C"
int
LLVMFuzzerTestOneInput
(
const
uint8_t
*
data
,
size_t
size
)
{
/* Run your code on data */
OHOS
::
FuzzDoRebootExt
(
data
,
size
);
return
0
;
}
test/fuzztest/DoRebootExt_fuzzer/DoRebootExt_fuzzer.h
0 → 100755
浏览文件 @
1b4a5685
/*
* Copyright (c) 2023 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.
*/
#ifndef TEST_FUZZTEST_DOREBOOTEXT_FUZZER_H
#define TEST_FUZZTEST_DOREBOOTEXT_FUZZER_H
#include "fuzz_utils.h"
#define FUZZ_PROJECT_NAME "DoRebootExt_fuzzer"
#endif
test/fuzztest/DoRebootExt_fuzzer/corpus/init
0 → 100755
浏览文件 @
1b4a5685
/*
* Copyright (c) 2023 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.
*/
FUZZ
\ No newline at end of file
test/fuzztest/DoRebootExt_fuzzer/project.xml
0 → 100755
浏览文件 @
1b4a5685
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2023 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>
100
</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>
30
</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>
2048
</rss_limit_mb>
</fuzztest>
</fuzz_config>
test/unittest/init/init_reboot_unittest.cpp
浏览文件 @
1b4a5685
...
...
@@ -99,6 +99,28 @@ HWTEST_F(InitRebootUnitTest, TestAddRebootCmdNormal, TestSize.Level1)
SystemWriteParam
(
"ohos.startup.powerctrl"
,
"reboot,flashd"
);
SystemWriteParam
(
"ohos.startup.powerctrl"
,
"reboot,flashd:1000000"
);
}
HWTEST_F
(
InitRebootUnitTest
,
TestRebootCmdExec
,
TestSize
.
Level1
)
{
PARAM_LOGE
(
"TestRebootCmdExec"
);
PluginExecCmdByName
(
"reboot"
,
"reboot"
);
PluginExecCmdByName
(
"reboot.shutdown"
,
"reboot,shutdown"
);
PluginExecCmdByName
(
"reboot.shutdown"
,
"reboot,shutdown:333333333333"
);
PluginExecCmdByName
(
"reboot.suspend"
,
"reboot,suspend"
);
PluginExecCmdByName
(
"reboot.charge"
,
"reboot,charge"
);
PluginExecCmdByName
(
"reboot.updater"
,
"reboot,updater"
);
PluginExecCmdByName
(
"reboot.updater"
,
"reboot,updater:2222222"
);
PluginExecCmdByName
(
"reboot.flashd"
,
"reboot,flashd"
);
PluginExecCmdByName
(
"reboot.flashd"
,
"reboot,flashd:1000000"
);
PluginExecCmdByName
(
"reboot.other"
,
"reboot,other"
);
PARAM_LOGE
(
"TestRebootCmdExec end"
);
int
ret
=
UpdateMiscMessage
(
"charge:wwwwwwwwwww"
,
"charge"
,
"charge:"
,
"boot_charge"
);
if
(
ret
==
0
)
{
ret
=
GetBootModeFromMisc
();
EXPECT_EQ
(
ret
,
GROUP_CHARGE
);
clearMisc
();
}
}
#endif
HWTEST_F
(
InitRebootUnitTest
,
TestInitReboot
,
TestSize
.
Level1
)
...
...
@@ -121,11 +143,7 @@ HWTEST_F(InitRebootUnitTest, TestInitReboot, TestSize.Level1)
ret
=
DoReboot
(
DEVICE_CMD_FREEZE
);
EXPECT_EQ
(
ret
,
0
);
ret
=
UpdateMiscMessage
(
"charge:wwwwwwwwwww"
,
"charge"
,
"charge:"
,
"boot_charge"
);
if
(
ret
==
0
)
{
ret
=
GetBootModeFromMisc
();
EXPECT_EQ
(
ret
,
GROUP_CHARGE
);
clearMisc
();
}
ret
=
DoRebootExt
(
"shutdown"
,
DEVICE_CMD_FREEZE
);
EXPECT_EQ
(
ret
,
0
);
}
}
// namespace init_ut
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录