Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
6e579a6b
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看板
提交
6e579a6b
编写于
7月 08, 2021
作者:
Z
zhong_ning
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug
Signed-off-by:
N
zhong_ning
<
zhong_ning@hoperun.com
>
上级
c0f5a512
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
39 addition
and
24 deletion
+39
-24
services/etc/init.cfg
services/etc/init.cfg
+5
-2
services/include/init_utils.h
services/include/init_utils.h
+1
-1
services/log/init_log.c
services/log/init_log.c
+1
-1
services/src/init_capability.c
services/src/init_capability.c
+8
-8
services/src/init_reboot.c
services/src/init_reboot.c
+17
-10
services/src/init_utils.c
services/src/init_utils.c
+7
-2
未找到文件。
services/etc/init.cfg
浏览文件 @
6e579a6b
...
...
@@ -5,7 +5,10 @@
"/init.${ro.hardware}.cfg",
"/init.Hi3516DV300.cfg",
"/init.usb.configfs.cfg",
"/init.${ro.zygote}.cfg"
"/init.${ro.zygote}.cfg",
"/init.Hi3516DV300.usb.cfg",
"/init.usb.configfs.cfg",
"/init.usb.cfg"
],
"jobs" : [{
"name" : "pre-init",
...
...
@@ -20,7 +23,7 @@
"mkdir /vendor",
"mkdir /data",
"mount ext4 /dev/block/platform/soc/10100000.himci.eMMC/by-name/vendor /vendor wait rdonly barrier=1",
"mount ext4 /dev/block/platform/soc/10100000.himci.eMMC/by-name/userdata /data wait nosuid nodev noatime barrier=1,data=o
rdered,noauto_da_alloc"
"mount ext4 /dev/block/platform/soc/10100000.himci.eMMC/by-name/userdata /data wait nosuid nodev noatime barrier=1,data=ordered,noauto_da_alloc"
]
}, {
"name" : "init",
...
...
services/include/init_utils.h
浏览文件 @
6e579a6b
...
...
@@ -37,7 +37,7 @@ int DecodeUid(const char *name);
void
CheckAndCreateDir
(
const
char
*
fileName
);
char
*
ReadFileToBuf
(
const
char
*
configFile
);
int
SplitString
(
char
*
srcPtr
,
char
**
dstPtr
,
int
maxNum
);
void
WaitForFile
(
const
char
*
source
,
int
maxCount
);
void
WaitForFile
(
const
char
*
source
,
unsigned
int
maxCount
);
#ifdef __cplusplus
#if __cplusplus
...
...
services/log/init_log.c
浏览文件 @
6e579a6b
...
...
@@ -42,7 +42,7 @@ void InitLog(const char *tag, InitLogLevel logLevel, const char *fileName, int l
if
(
logLevel
<
g_logLevel
)
{
return
;
}
//
????stdout??????????
//
可以替换stdout这个为对应的文件句柄
time_t
logTime
;
time
(
&
logTime
);
struct
tm
*
t
=
gmtime
(
&
logTime
);
...
...
services/src/init_capability.c
浏览文件 @
6e579a6b
...
...
@@ -85,7 +85,7 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ)
for
(;
i
<
curServ
->
servPerm
.
capsCnt
;
++
i
)
{
if
(
cJSON_GetArrayItem
(
filedJ
,
i
)
==
NULL
||
!
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
filedJ
,
i
))
||
strlen
(
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
filedJ
,
i
)))
<=
0
)
{
// check all errors
INIT_LOGE
(
"
[init]
service=%s, parse item[%d] as string, error.
\n
"
,
curServ
->
name
,
i
);
INIT_LOGE
(
"service=%s, parse item[%d] as string, error.
\n
"
,
curServ
->
name
,
i
);
break
;
}
char
*
fieldStr
=
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
filedJ
,
i
));
...
...
@@ -99,12 +99,12 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ)
if
(
j
<
mapSize
)
{
curServ
->
servPerm
.
caps
[
i
]
=
g_capStrCapNum
[
j
].
CapNum
;
}
else
{
INIT_LOGE
(
"
[init]
service=%s, CapbilityName=%s, error.
\n
"
,
curServ
->
name
,
fieldStr
);
INIT_LOGE
(
"service=%s, CapbilityName=%s, error.
\n
"
,
curServ
->
name
,
fieldStr
);
break
;
}
if
(
curServ
->
servPerm
.
caps
[
i
]
>
CAP_LAST_CAP
&&
curServ
->
servPerm
.
caps
[
i
]
!=
FULL_CAP
)
{
// resources will be released by function: ReleaseServiceMem
INIT_LOGE
(
"
[init]
service=%s, cap = %d, error.
\n
"
,
curServ
->
name
,
curServ
->
servPerm
.
caps
[
i
]);
INIT_LOGE
(
"service=%s, cap = %d, error.
\n
"
,
curServ
->
name
,
curServ
->
servPerm
.
caps
[
i
]);
return
SERVICE_FAILURE
;
}
}
...
...
@@ -121,7 +121,7 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
return
SERVICE_SUCCESS
;
}
if
(
!
cJSON_IsArray
(
filedJ
))
{
INIT_LOGE
(
"
[init]
service=%s, caps is not a list, error.
\n
"
,
curServ
->
name
);
INIT_LOGE
(
"service=%s, caps is not a list, error.
\n
"
,
curServ
->
name
);
return
SERVICE_FAILURE
;
}
// caps array does not exist, means do not need any capability
...
...
@@ -130,13 +130,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
return
SERVICE_SUCCESS
;
}
if
(
capsCnt
>
MAX_CAPS_CNT_FOR_ONE_SERVICE
)
{
INIT_LOGE
(
"
[init],
service=%s, too many caps[cnt %d] for one service, max is %d.
\n
"
,
INIT_LOGE
(
"service=%s, too many caps[cnt %d] for one service, max is %d.
\n
"
,
curServ
->
name
,
capsCnt
,
MAX_CAPS_CNT_FOR_ONE_SERVICE
);
return
SERVICE_FAILURE
;
}
curServ
->
servPerm
.
caps
=
(
unsigned
int
*
)
malloc
(
sizeof
(
unsigned
int
)
*
capsCnt
);
if
(
curServ
->
servPerm
.
caps
==
NULL
)
{
INIT_LOGE
(
"
[init]
GetServiceCaps, service=%s, malloc error.
\n
"
,
curServ
->
name
);
INIT_LOGE
(
"GetServiceCaps, service=%s, malloc error.
\n
"
,
curServ
->
name
);
return
SERVICE_FAILURE
;
}
curServ
->
servPerm
.
capsCnt
=
capsCnt
;
...
...
@@ -145,13 +145,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
cJSON
*
capJ
=
cJSON_GetArrayItem
(
filedJ
,
i
);
if
(
!
cJSON_IsNumber
(
capJ
)
||
cJSON_GetNumberValue
(
capJ
)
<
0
)
{
// resources will be released by function: ReleaseServiceMem
INIT_LOGI
(
"
[init],
service=%s, Capbility is not a number or < 0, error.
\n
"
,
curServ
->
name
);
INIT_LOGI
(
"service=%s, Capbility is not a number or < 0, error.
\n
"
,
curServ
->
name
);
break
;
}
curServ
->
servPerm
.
caps
[
i
]
=
(
unsigned
int
)
cJSON_GetNumberValue
(
capJ
);
if
(
curServ
->
servPerm
.
caps
[
i
]
>
CAP_LAST_CAP
&&
curServ
->
servPerm
.
caps
[
i
]
!=
FULL_CAP
)
{
// CAP_LAST_CAP = 37
// resources will be released by function: ReleaseServiceMem
INIT_LOGE
(
"
[init]
service=%s, caps = %d, error.
\n
"
,
curServ
->
name
,
curServ
->
servPerm
.
caps
[
i
]);
INIT_LOGE
(
"service=%s, caps = %d, error.
\n
"
,
curServ
->
name
,
curServ
->
servPerm
.
caps
[
i
]);
return
SERVICE_FAILURE
;
}
}
...
...
services/src/init_reboot.c
浏览文件 @
6e579a6b
...
...
@@ -80,7 +80,7 @@ static int GetMountStatusForMountPoint(const char *mountPoint)
const
char
*
mountFile
=
"/proc/mounts"
;
FILE
*
fp
=
fopen
(
mountFile
,
"r"
);
if
(
fp
==
NULL
)
{
INIT_LOGE
(
"
[init]
DoReboot %s can't open.
\n
"
,
mountPoint
);
INIT_LOGE
(
"DoReboot %s can't open.
\n
"
,
mountPoint
);
return
1
;
}
...
...
@@ -103,24 +103,32 @@ static int GetMountStatusForMountPoint(const char *mountPoint)
void
DoReboot
(
const
char
*
value
)
{
if
(
value
==
NULL
)
{
INIT_LOGE
(
"
[init]
DoReboot value = NULL
\n
"
);
INIT_LOGE
(
"DoReboot value = NULL
\n
"
);
return
;
}
INIT_LOGI
(
"
[init]
DoReboot value = %s
\n
"
,
value
);
INIT_LOGI
(
"DoReboot value = %s
\n
"
,
value
);
if
(
strlen
(
value
)
>
MAX_VALUE_LENGTH
)
{
INIT_LOGE
(
"
[init]
DoReboot reboot value error, value = %s.
\n
"
,
value
);
INIT_LOGE
(
"DoReboot reboot value error, value = %s.
\n
"
,
value
);
return
;
}
const
char
*
valueData
=
NULL
;
if
(
strncmp
(
value
,
"reboot,"
,
strlen
(
"reboot,"
))
!=
0
)
{
INIT_LOGE
(
"
[init]
DoReboot reboot value = %s, must started with reboot ,error.
\n
"
,
value
);
INIT_LOGE
(
"DoReboot reboot value = %s, must started with reboot ,error.
\n
"
,
value
);
return
;
}
else
{
valueData
=
value
+
strlen
(
"reboot,"
);
}
if
(
strncmp
(
valueData
,
"shutdown"
,
strlen
(
"shutdown"
))
!=
0
&&
strncmp
(
valueData
,
"updater:"
,
strlen
(
"updater:"
))
!=
0
&&
strncmp
(
valueData
,
"updater"
,
strlen
(
"updater"
))
!=
0
&&
strncmp
(
valueData
,
"NoArgument"
,
strlen
(
"NoArgument"
))
!=
0
)
{
INIT_LOGE
(
"DoReboot value = %s, parameters error.
\n
"
,
value
);
return
;
}
StopAllServicesBeforeReboot
();
if
(
GetMountStatusForMountPoint
(
"/vendor"
))
{
if
(
umount
(
"/vendor"
)
!=
0
)
{
INIT_LOGE
(
"DoReboot umount vendor failed! errno = %d.
\n
"
,
errno
);
...
...
@@ -131,7 +139,6 @@ void DoReboot(const char *value)
INIT_LOGE
(
"DoReboot umount data failed! errno = %d.
\n
"
,
errno
);
}
}
StopAllServicesBeforeReboot
();
// "shutdown"
if
(
strncmp
(
valueData
,
"shutdown"
,
strlen
(
"shutdown"
))
==
0
)
{
int
ret
=
reboot
(
RB_POWER_OFF
);
...
...
@@ -145,7 +152,7 @@ void DoReboot(const char *value)
struct
RBMiscUpdateMessage
msg
;
bool
ret
=
RBMiscReadUpdaterMessage
(
miscFile
,
&
msg
);
if
(
!
ret
)
{
INIT_LOGE
(
"
[init]
DoReboot RBMiscReadUpdaterMessage error.
\n
"
);
INIT_LOGE
(
"DoReboot RBMiscReadUpdaterMessage error.
\n
"
);
return
;
}
const
int
commandSize
=
12
;
...
...
@@ -155,13 +162,13 @@ void DoReboot(const char *value)
if
(
strlen
(
valueData
)
>
strlen
(
"updater:"
)
&&
strncmp
(
valueData
,
"updater:"
,
strlen
(
"updater:"
))
==
0
)
{
const
char
*
p
=
valueData
+
strlen
(
"updater:"
);
if
(
snprintf
(
msg
.
update
,
MAX_UPDATE_SIZE
,
"%s"
,
p
)
>
MAX_UPDATE_SIZE
)
{
INIT_LOGE
(
"
[init]
DoReboot updater: RBMiscWriteUpdaterMessage error
\n
"
);
INIT_LOGE
(
"DoReboot updater: RBMiscWriteUpdaterMessage error
\n
"
);
return
;
}
msg
.
update
[
MAX_UPDATE_SIZE
-
1
]
=
0
;
ret
=
RBMiscWriteUpdaterMessage
(
miscFile
,
&
msg
);
if
(
true
!=
ret
)
{
INIT_LOGE
(
"
[init]
DoReboot updater: RBMiscWriteUpdaterMessage error
\n
"
);
INIT_LOGE
(
"DoReboot updater: RBMiscWriteUpdaterMessage error
\n
"
);
return
;
}
ret
=
reboot
(
RB_AUTOBOOT
);
...
...
@@ -173,7 +180,7 @@ void DoReboot(const char *value)
if
(
strlen
(
valueData
)
==
strlen
(
"updater"
)
&&
strncmp
(
valueData
,
"updater"
,
strlen
(
"updater"
))
==
0
)
{
ret
=
RBMiscWriteUpdaterMessage
(
miscFile
,
&
msg
);
if
(
true
!=
ret
)
{
INIT_LOGE
(
"
[init]
DoReboot updater RBMiscWriteUpdaterMessage error
\n
"
);
INIT_LOGE
(
"DoReboot updater RBMiscWriteUpdaterMessage error
\n
"
);
return
;
}
ret
=
reboot
(
RB_AUTOBOOT
);
...
...
services/src/init_utils.c
浏览文件 @
6e579a6b
...
...
@@ -34,6 +34,7 @@
#include "init_utils.h"
#include "securec.h"
#define WAIT_MAX_COUNT 10
#define MAX_BUF_SIZE 1024
#ifdef STARTUP_UT
#define LOG_FILE_NAME "/media/sf_ubuntu/test/log.txt"
...
...
@@ -179,11 +180,15 @@ int SplitString(char *srcPtr, char **dstPtr, int maxNum)
return
num
;
}
void
WaitForFile
(
const
char
*
source
,
int
maxCount
)
void
WaitForFile
(
const
char
*
source
,
unsigned
int
maxCount
)
{
if
(
maxCount
>
WAIT_MAX_COUNT
)
{
INIT_LOGE
(
"WaitForFile max time is 50ms"
);
return
;
}
struct
stat
sourceInfo
;
unsigned
int
waitTime
=
500000
;
int
count
=
0
;
unsigned
int
count
=
0
;
do
{
usleep
(
waitTime
);
count
++
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录