Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
3fb12c30
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看板
提交
3fb12c30
编写于
3月 03, 2022
作者:
X
xionglei6
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add: 添加suspend支持
Signed-off-by:
N
xionglei6
<
xionglei6@huawei.com
>
上级
dd66b3ad
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
106 addition
and
60 deletion
+106
-60
interfaces/innerkits/fs_manager/fstab.c
interfaces/innerkits/fs_manager/fstab.c
+6
-5
services/BUILD.gn
services/BUILD.gn
+7
-0
services/begetctl/init_cmd_reboot.c
services/begetctl/init_cmd_reboot.c
+2
-0
services/begetctl/main.c
services/begetctl/main.c
+3
-0
services/etc/init.cfg
services/etc/init.cfg
+0
-9
services/etc/init.reboot.cfg
services/etc/init.reboot.cfg
+23
-0
services/init/include/init_service.h
services/init/include/init_service.h
+1
-0
services/init/init_service_manager.c
services/init/init_service_manager.c
+2
-2
services/init/standard/init_cmds.c
services/init/standard/init_cmds.c
+7
-1
services/init/standard/init_reboot.c
services/init/standard/init_reboot.c
+49
-41
services/init/standard/init_signal_handler.c
services/init/standard/init_signal_handler.c
+4
-1
services/utils/init_utils.c
services/utils/init_utils.c
+2
-1
未找到文件。
interfaces/innerkits/fs_manager/fstab.c
浏览文件 @
3fb12c30
...
...
@@ -190,13 +190,14 @@ Fstab *ReadFstabFromFile(const char *file, bool procMounts)
ssize_t
readn
=
0
;
Fstab
*
fstab
=
NULL
;
FILE
*
fp
=
NULL
;
char
*
realPath
=
GetRealPath
(
file
);
if
(
realPath
==
NULL
)
{
BEGET_LOGE
(
"Invalid file"
);
return
NULL
;
if
(
realPath
!=
NULL
)
{
fp
=
fopen
(
realPath
,
"r"
);
free
(
realPath
);
}
else
{
fp
=
fopen
(
file
,
"r"
);
// no file system, can not get real path
}
FILE
*
fp
=
fopen
(
realPath
,
"r"
);
free
(
realPath
);
if
(
fp
==
NULL
)
{
BEGET_LOGE
(
"Open %s failed, err = %d"
,
file
,
errno
);
return
NULL
;
...
...
services/BUILD.gn
浏览文件 @
3fb12c30
...
...
@@ -301,12 +301,19 @@ if (defined(ohos_lite)) {
part_name = "init"
}
ohos_prebuilt_etc("init.reboot") {
source = "//base/startup/init_lite/services/etc/init.reboot.cfg"
part_name = "init"
module_install_dir = "etc/init"
}
group("init_etc") {
deps = [
":boot.group",
":charing.group",
":group",
":init.cfg",
":init.reboot",
":init.usb.cfg",
":init.usb.configfs.cfg",
":ohos.para",
...
...
services/begetctl/init_cmd_reboot.c
浏览文件 @
3fb12c30
...
...
@@ -29,6 +29,7 @@ static int main_cmd(BShellHandle shell, int argc, char* argv[])
if
(
argc
==
REBOOT_CMD_NUMBER
&&
strcmp
(
argv
[
1
],
"shutdown"
)
!=
0
&&
strcmp
(
argv
[
1
],
"updater"
)
!=
0
&&
strcmp
(
argv
[
1
],
"suspend"
)
!=
0
&&
strcmp
(
argv
[
1
],
"flashd"
)
!=
0
&&
#ifdef INIT_TEST
strcmp
(
argv
[
1
],
"charing"
)
!=
0
&&
...
...
@@ -63,6 +64,7 @@ MODULE_CONSTRUCTOR(void)
CmdInfo
infos
[]
=
{
{
"reboot"
,
main_cmd
,
"reboot system"
,
"reboot"
,
""
},
{
"reboot"
,
main_cmd
,
"shutdown system"
,
"reboot shutdown"
,
""
},
{
"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]"
,
""
},
{
"reboot"
,
main_cmd
,
"reboot and boot into flashd"
,
"reboot flashd"
,
""
},
...
...
services/begetctl/main.c
浏览文件 @
3fb12c30
...
...
@@ -64,6 +64,9 @@ int main(int argc, char *argv[])
number
=
argc
-
1
;
args
=
argv
+
1
;
}
if
(
number
>=
1
&&
strcmp
(
args
[
0
],
"devctl"
)
==
0
)
{
memcpy_s
(
args
[
0
],
strlen
(
args
[
0
]),
"reboot"
,
strlen
(
"reboot"
));
}
SetInitLogLevel
(
0
);
BShellParamCmdRegister
(
g_handle
,
0
);
#ifdef INIT_TEST
...
...
services/etc/init.cfg
浏览文件 @
3fb12c30
...
...
@@ -428,15 +428,6 @@
"chmod 0773 /data/misc/trace",
"chmod 0775 /data/misc/wmtrace"
]
}, {
"name" : "reboot",
"cmds" : [
"stopAllServices ",
"sync ",
"umount /vendor",
"umount /data MNT_FORCE",
"sync "
]
}
],
"services" : [{
...
...
services/etc/init.reboot.cfg
0 → 100755
浏览文件 @
3fb12c30
{
"jobs" : [{
"name" : "reboot",
"cmds" : [
"stopAllServices true",
"sync ",
"umount /vendor",
"umount /data MNT_FORCE",
"sync "
]
}, {
"name" : "suspend",
"cmds" : [
"stopAllServices false",
"sync ",
"umount /vendor",
"umount /data MNT_FORCE",
"sync "
]
}
],
"services" : []
}
services/init/include/init_service.h
浏览文件 @
3fb12c30
...
...
@@ -51,6 +51,7 @@ extern "C" {
#define SERVICE_ATTR_DYNAMIC 0x100 // dynamic service
#define SERVICE_ATTR_ONDEMAND 0x200 // ondemand, manage socket by init
#define SERVICE_ATTR_TIMERSTART 0x400 // Mark a service will be started by timer
#define SERVICE_ATTR_NEEDWAIT 0x800 // Mark a service will be started by timer
#define MAX_SERVICE_NAME 32
#define MAX_APL_NAME 32
...
...
services/init/init_service_manager.c
浏览文件 @
3fb12c30
...
...
@@ -961,7 +961,7 @@ void StopAllServices(int flags, const char **exclude, int size,
int
(
*
filter
)(
const
Service
*
service
,
const
char
**
exclude
,
int
size
))
{
Service
*
service
=
GetServiceByName
(
"appspawn"
);
if
(
service
!=
NULL
&&
service
->
pid
!=
0
)
{
if
(
((
SERVICE_ATTR_NEEDWAIT
&
flags
)
==
SERVICE_ATTR_NEEDWAIT
)
&&
service
!=
NULL
&&
service
->
pid
!=
0
)
{
waitpid
(
service
->
pid
,
0
,
0
);
}
...
...
@@ -977,7 +977,7 @@ void StopAllServices(int flags, const char **exclude, int size,
node
=
GetNextGroupNode
(
NODE_TYPE_SERVICES
,
node
);
continue
;
}
service
->
attribute
|=
flags
;
service
->
attribute
|=
(
flags
&
SERVICE_ATTR_INVALID
)
;
int
ret
=
ServiceStop
(
service
);
if
(
ret
!=
SERVICE_SUCCESS
)
{
INIT_LOGE
(
"Service %s stop failed!"
,
service
->
name
);
...
...
services/init/standard/init_cmds.c
浏览文件 @
3fb12c30
...
...
@@ -304,7 +304,13 @@ static int FilterService(const Service *service, const char **exclude, int size)
static
void
DoStopAllServices
(
const
struct
CmdArgs
*
ctx
)
{
StopAllServices
(
SERVICE_ATTR_INVALID
,
(
const
char
**
)
ctx
->
argv
,
ctx
->
argc
,
FilterService
);
int
flags
=
SERVICE_ATTR_INVALID
;
if
(
ctx
->
argc
>=
1
&&
strcmp
(
ctx
->
argv
[
0
],
"true"
)
==
0
)
{
flags
|=
SERVICE_ATTR_NEEDWAIT
;
StopAllServices
(
flags
,
(
const
char
**
)(
&
ctx
->
argv
[
1
]),
ctx
->
argc
-
1
,
FilterService
);
}
else
{
StopAllServices
(
flags
,
(
const
char
**
)
ctx
->
argv
,
ctx
->
argc
,
FilterService
);
}
return
;
}
...
...
services/init/standard/init_reboot.c
浏览文件 @
3fb12c30
...
...
@@ -131,89 +131,98 @@ static int CheckAndRebootToUpdater(const char *valueData, const char *cmd,
INIT_ERROR_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to format update for %s."
,
cmd
);
}
ret
=
-
1
;
if
(
RBMiscWriteUpdaterMessage
(
miscFile
,
&
msg
)
==
0
)
{
ret
=
0
;
#ifndef STARTUP_INIT_TEST
ret
=
reboot
(
RB_AUTOBOOT
);
#endif
return
0
;
}
return
ret
;
return
-
1
;
}
int
DoRebootCmd
(
const
char
*
cmd
,
const
char
*
opt
)
static
int
DoRebootCmd
(
const
char
*
cmd
,
const
char
*
opt
)
{
// by job to stop service and unmount
DoJobNow
(
"reboot"
);
#ifndef PRODUCT_RK
return
CheckAndRebootToUpdater
(
NULL
,
"reboot"
,
NULL
,
NULL
);
#else
reboot
(
RB_AUTOBOOT
);
return
0
;
int
ret
=
CheckAndRebootToUpdater
(
NULL
,
"reboot"
,
NULL
,
NULL
);
if
(
ret
==
0
)
{
#ifndef STARTUP_INIT_TEST
return
reboot
(
RB_AUTOBOOT
);
#endif
}
return
0
;
}
int
DoShutdownCmd
(
const
char
*
cmd
,
const
char
*
opt
)
static
int
DoShutdownCmd
(
const
char
*
cmd
,
const
char
*
opt
)
{
// by job to stop service and unmount
DoJobNow
(
"reboot"
);
int
ret
=
CheckAndRebootToUpdater
(
NULL
,
"reboot"
,
NULL
,
NULL
);
if
(
ret
==
0
)
{
#ifndef STARTUP_INIT_TEST
return
reboot
(
RB_POWER_OFF
);
#else
return
0
;
return
reboot
(
RB_POWER_OFF
);
#endif
}
return
0
;
}
int
DoUpdaterCmd
(
const
char
*
cmd
,
const
char
*
opt
)
static
int
DoUpdaterCmd
(
const
char
*
cmd
,
const
char
*
opt
)
{
// by job to stop service and unmount
DoJobNow
(
"reboot"
);
return
CheckAndRebootToUpdater
(
opt
,
"updater"
,
"updater:"
,
"boot_updater"
);
int
ret
=
CheckAndRebootToUpdater
(
opt
,
"updater"
,
"updater:"
,
"boot_updater"
);
if
(
ret
==
0
)
{
#ifndef STARTUP_INIT_TEST
return
reboot
(
RB_AUTOBOOT
);
#endif
}
return
0
;
}
int
DoFlashdCmd
(
const
char
*
cmd
,
const
char
*
opt
)
static
int
DoFlashdCmd
(
const
char
*
cmd
,
const
char
*
opt
)
{
// by job to stop service and unmount
DoJobNow
(
"reboot"
);
return
CheckAndRebootToUpdater
(
opt
,
"flash"
,
"flash:"
,
"boot_flash"
);
int
ret
=
CheckAndRebootToUpdater
(
opt
,
"flash"
,
"flash:"
,
"boot_flash"
);
if
(
ret
==
0
)
{
#ifndef STARTUP_INIT_TEST
return
reboot
(
RB_AUTOBOOT
);
#endif
}
return
0
;
}
#ifdef PRODUCT_RK
int
DoLoaderCmd
(
const
char
*
cmd
,
const
char
*
opt
)
static
int
DoLoaderCmd
(
const
char
*
cmd
,
const
char
*
opt
)
{
syscall
(
__NR_reboot
,
REBOOT_MAGIC1
,
REBOOT_MAGIC2
,
REBOOT_CMD_RESTART2
,
"loader"
);
return
0
;
}
#endif
int
DoSuspendCmd
(
const
char
*
cmd
,
const
char
*
opt
)
static
int
DoSuspendCmd
(
const
char
*
cmd
,
const
char
*
opt
)
{
// by job to stop service and unmount
DoJobNow
(
"suspend"
);
int
ret
=
CheckAndRebootToUpdater
(
NULL
,
"reboot"
,
NULL
,
NULL
);
if
(
ret
==
0
)
{
#ifndef STARTUP_INIT_TEST
return
reboot
(
RB_POWER_OFF
);
#else
return
0
;
INIT_LOGE
(
"DoSuspendCmd %s RB_SW_SUSPEND."
,
cmd
);
return
reboot
(
RB_SW_SUSPEND
);
#endif
}
int
DoFreezeCmd
(
const
char
*
cmd
,
const
char
*
opt
)
{
// by job to stop service and unmount
DoJobNow
(
"freeze"
);
#ifndef STARTUP_INIT_TEST
return
reboot
(
RB_POWER_OFF
);
#else
}
return
0
;
#endif
}
#ifdef INIT_TEST
int
DoCharingCmd
()
static
int
DoCharingCmd
()
{
// by job to stop service and unmount
DoJobNow
(
"reboot"
);
return
CheckAndRebootToUpdater
(
NULL
,
"charing"
,
"charing:"
,
"boot_charing"
);
int
ret
=
CheckAndRebootToUpdater
(
NULL
,
"charing"
,
"charing:"
,
"boot_charing"
);
if
(
ret
==
0
)
{
#ifndef STARTUP_INIT_TEST
return
reboot
(
RB_AUTOBOOT
);
#endif
}
return
0
;
}
#endif
...
...
@@ -230,7 +239,6 @@ struct {
{
"loader"
,
DoLoaderCmd
},
#endif
{
"suspend"
,
DoSuspendCmd
},
{
"freeze"
,
DoFreezeCmd
},
#ifdef INIT_TEST
{
"charing"
,
DoCharingCmd
}
#endif
...
...
@@ -249,14 +257,14 @@ void ExecReboot(const char *value)
return
;
}
INIT_LOG
E
(
"ExecReboot %s."
,
cmd
);
INIT_LOG
I
(
"ExecReboot %s param %s."
,
cmd
,
value
);
for
(
int
i
=
0
;
i
<
(
int
)
ARRAY_LENGTH
(
g_rebootCmd
);
i
++
)
{
if
(
strncmp
(
cmd
,
g_rebootCmd
[
i
].
cmdName
,
strlen
(
g_rebootCmd
[
i
].
cmdName
))
==
0
)
{
int
ret
=
g_rebootCmd
[
i
].
doCmd
(
cmd
,
cmd
);
INIT_LOGI
(
"Reboot %s %s
."
,
value
,
(
ret
==
0
)
?
"success"
:
"fail"
);
INIT_LOGI
(
"Reboot %s %s
errno %d ."
,
cmd
,
(
ret
==
0
)
?
"success"
:
"fail"
,
errno
);
return
;
}
}
INIT_LOGE
(
"Invalid rebot cmd %s."
,
value
);
INIT_LOGE
(
"Invalid rebo
o
t cmd %s."
,
value
);
return
;
}
services/init/standard/init_signal_handler.c
浏览文件 @
3fb12c30
...
...
@@ -17,6 +17,7 @@
#include "init_adapter.h"
#include "init_log.h"
#include "init_param.h"
#include "init_service_manager.h"
#include "loop_event.h"
...
...
@@ -48,7 +49,9 @@ static void ProcessSignal(const struct signalfd_siginfo *siginfo)
}
case
SIGTERM
:
{
INIT_LOGI
(
"SigHandler, SIGTERM received."
);
StopAllServices
(
0
,
NULL
,
0
,
NULL
);
SystemWriteParam
(
"startup.device.ctl"
,
"stop"
);
// exec reboot use toybox reboot cmd
ExecReboot
(
"reboot"
);
break
;
}
default:
...
...
services/utils/init_utils.c
浏览文件 @
3fb12c30
...
...
@@ -168,8 +168,9 @@ int GetProcCmdlineValue(const char *name, const char *buffer, char *value, int l
endIndex
=
i
;
break
;
}
if
(
*
tmp
==
' '
)
{
if
(
*
tmp
==
' '
||
*
tmp
==
'\n'
||
*
tmp
==
'\r'
||
*
tmp
==
'\t'
)
{
endIndex
=
i
;
break
;
}
if
(
*
tmp
==
'='
)
{
if
(
endIndex
!=
0
)
{
// for root=uuid=xxxx
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录