Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
670f0bab
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看板
提交
670f0bab
编写于
1月 24, 2022
作者:
熊
熊磊
提交者:
Gitee
1月 24, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of gitee.com:openharmony/startup_init_lite into init119_3
Signed-off-by:
N
xionglei
<
xionglei6@huawei.com
>
上级
b322f27f
c353b0c4
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
7 addition
and
115 deletion
+7
-115
services/etc/init.cfg
services/etc/init.cfg
+1
-0
services/etc/init.without_two_stages.cfg
services/etc/init.without_two_stages.cfg
+1
-0
services/init/include/init_service.h
services/init/include/init_service.h
+0
-7
services/init/include/init_service_manager.h
services/init/include/init_service_manager.h
+0
-3
services/init/init_common_service.c
services/init/init_common_service.c
+0
-40
services/init/init_service_manager.c
services/init/init_service_manager.c
+4
-60
test/unittest/BUILD.gn
test/unittest/BUILD.gn
+0
-1
test/unittest/common/BUILD.gn
test/unittest/common/BUILD.gn
+1
-4
未找到文件。
services/etc/init.cfg
浏览文件 @
670f0bab
...
...
@@ -64,6 +64,7 @@
"chmod 0770 /config/sdcardfs",
"chown system package_info /config/sdcardfs",
"symlink /storage/self/primary /sdcard",
"mkdir /mnt/sandbox 0711 root root",
"write /proc/sys/kernel/panic_on_oops 1",
"write /proc/sys/kernel/hung_task_timeout_secs 0",
"write /proc/cpu/alignment 4",
...
...
services/etc/init.without_two_stages.cfg
浏览文件 @
670f0bab
...
...
@@ -64,6 +64,7 @@
"chmod 0770 /config/sdcardfs",
"chown system package_info /config/sdcardfs",
"symlink /storage/self/primary /sdcard",
"mkdir /mnt/sandbox 0711 root root",
"write /proc/sys/kernel/panic_on_oops 1",
"write /proc/sys/kernel/hung_task_timeout_secs 0",
"write /proc/cpu/alignment 4",
...
...
services/init/include/init_service.h
浏览文件 @
670f0bab
...
...
@@ -46,7 +46,6 @@ extern "C" {
#define SERVICE_ATTR_DYNAMIC 0x100 // dynamic service
#define SERVICE_ATTR_ONDEMAND 0x200 // ondemand, manage socket by init
#define MAX_APL_NAME 32
#define MAX_SERVICE_NAME 32
#define MAX_APL_NAME 32
#define MAX_JOB_NAME 128
...
...
@@ -76,11 +75,6 @@ typedef enum {
END_RECV_READY
,
}
ServiceEndMode
;
typedef
struct
{
int
*
cpus
;
int
cpuNum
;
}
CpuArgs
;
typedef
struct
{
uid_t
uID
;
gid_t
*
gIDArray
;
...
...
@@ -122,7 +116,6 @@ typedef struct Service_ {
int
endMode
:
4
;
// preFork/ fork / exec / ready
char
apl
[
MAX_APL_NAME
+
1
];
ServiceArgs
capsArgs
;
CpuArgs
cpuInfo
;
Perms
servPerm
;
ServiceArgs
pathArgs
;
ServiceArgs
extraArgs
;
...
...
services/init/include/init_service_manager.h
浏览文件 @
670f0bab
...
...
@@ -33,9 +33,6 @@ extern "C" {
#define CRITICAL_STR_IN_CFG "critical"
#define DISABLED_STR_IN_CFG "disabled"
#define CONSOLE_STR_IN_CFG "console"
#define D_CAPS_STR_IN_CFG "d-caps"
#define APL_STR_IN_CFG "apl"
#define CPU_CORE_STAR_IN_CFG "cpucore"
#define MAX_SERVICES_CNT_IN_FILE 100
...
...
services/init/init_common_service.c
浏览文件 @
670f0bab
...
...
@@ -18,8 +18,6 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <stdio.h>
#ifdef __MUSL__
#include <stropts.h>
#endif
...
...
@@ -255,41 +253,6 @@ static void PublishHoldFds(Service *service)
}
}
static
int
SetAffinityBetweenProcAndCore
(
pid_t
pid
,
int
cpuIndex
)
{
cpu_set_t
setMask
;
CPU_ZERO
(
&
setMask
);
CPU_SET
(
cpuIndex
,
&
setMask
);
int
ret
=
sched_setaffinity
(
pid
,
sizeof
(
cpu_set_t
),
&
setMask
);
if
(
ret
!=
0
)
{
INIT_LOGI
(
"Set affinity between process(pid=%d) with CPU's core %d failed"
,
pid
,
cpuIndex
);
return
SERVICE_FAILURE
;
}
else
{
INIT_LOGE
(
"Set affinity between process(pid=%d) with CPU's core %d successfully"
,
pid
,
cpuIndex
);
}
return
SERVICE_SUCCESS
;
}
static
int
BindCpuCore
(
Service
*
service
)
{
if
(
service
==
NULL
||
service
->
cpuInfo
.
cpuNum
<=
0
)
{
return
SERVICE_SUCCESS
;
}
long
cpuNum
=
sysconf
(
_SC_NPROCESSORS_CONF
);
INIT_ERROR_CHECK
(
service
->
cpuInfo
.
cpuNum
<=
cpuNum
,
return
SERVICE_FAILURE
,
"%s cpus cores exceeds total number of device cores"
,
service
->
name
);
int
index
=
0
;
for
(
int
i
=
0
;
i
<
service
->
cpuInfo
.
cpuNum
;
i
++
)
{
index
=
(
int
)
service
->
cpuInfo
.
cpus
[
i
];
if
((
int
)
cpuNum
<=
index
)
{
INIT_LOGW
(
"%s core number %d of CPU cores does not exist"
,
service
->
name
,
index
);
continue
;
}
(
void
)
SetAffinityBetweenProcAndCore
(
getpid
(),
index
);
}
return
SERVICE_SUCCESS
;
}
int
ServiceStart
(
Service
*
service
)
{
INIT_ERROR_CHECK
(
service
!=
NULL
,
return
SERVICE_FAILURE
,
"start service failed! null ptr."
);
...
...
@@ -326,9 +289,6 @@ int ServiceStart(Service *service)
OpenConsole
();
}
PublishHoldFds
(
service
);
// bind cpu core
INIT_CHECK_ONLY_ELOG
(
BindCpuCore
(
service
)
==
SERVICE_SUCCESS
,
"binding core number failed for service %s"
,
service
->
name
);
// permissions
INIT_ERROR_CHECK
(
SetPerms
(
service
)
==
SERVICE_SUCCESS
,
_exit
(
PROCESS_EXIT_CODE
),
"service %s exit! set perms failed! err %d."
,
service
->
name
,
errno
);
...
...
services/init/init_service_manager.c
浏览文件 @
670f0bab
...
...
@@ -168,13 +168,7 @@ void ReleaseService(Service *service)
}
FreeServiceArg
(
&
service
->
pathArgs
);
FreeServiceArg
(
&
service
->
writePidArgs
);
FreeServiceArg
(
&
service
->
capsArgs
);
if
(
service
->
cpuInfo
.
cpus
!=
NULL
)
{
free
(
service
->
cpuInfo
.
cpus
);
service
->
cpuInfo
.
cpus
=
NULL
;
}
service
->
cpuInfo
.
cpuNum
=
0
;
if
(
service
->
servPerm
.
caps
!=
NULL
)
{
free
(
service
->
servPerm
.
caps
);
service
->
servPerm
.
caps
=
NULL
;
...
...
@@ -236,12 +230,7 @@ static int GetServiceArgs(const cJSON *argJson, const char *name, int maxCount,
for
(
int
i
=
0
;
i
<
count
+
1
;
++
i
)
{
args
->
argv
[
i
]
=
NULL
;
}
// ServiceArgs have a variety of uses, some requiring a NULL ending, some not
if
(
strcmp
(
name
,
D_CAPS_STR_IN_CFG
)
!=
0
)
{
args
->
count
=
count
+
1
;
}
else
{
args
->
count
=
count
;
}
args
->
count
=
count
+
1
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
char
*
curParam
=
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
obj
,
i
));
INIT_ERROR_CHECK
(
curParam
!=
NULL
,
return
SERVICE_FAILURE
,
"Invalid arg %d"
,
i
);
...
...
@@ -519,7 +508,7 @@ static int CheckServiceKeyName(const cJSON *curService)
char
*
cfgServiceKeyList
[]
=
{
"name"
,
"path"
,
"uid"
,
"gid"
,
"once"
,
"importance"
,
"caps"
,
"disabled"
,
"writepid"
,
"critical"
,
"socket"
,
"console"
,
"dynamic"
,
"file"
,
"ondemand"
,
"d-caps"
,
"apl"
,
"jobs"
,
"start-mode"
,
"end-mode"
,
"cpucore"
,
"d-caps"
,
"apl"
,
"jobs"
,
"start-mode"
,
"end-mode"
,
#ifdef WITH_SELINUX
SECON_STR_IN_CFG
,
#endif // WITH_SELINUX
...
...
@@ -640,49 +629,6 @@ int GetCritical(const cJSON *curArrItem, Service *curServ, const char *attrName
return
SERVICE_SUCCESS
;
}
static
int
Comparefunc
(
const
void
*
before
,
const
void
*
after
)
{
return
(
*
(
int
*
)
before
-
*
(
int
*
)
after
);
}
static
int
GetCpuArgs
(
const
cJSON
*
argJson
,
const
char
*
name
,
CpuArgs
*
args
)
{
INIT_ERROR_CHECK
(
argJson
!=
NULL
,
return
SERVICE_FAILURE
,
"Invalid argJson"
);
cJSON
*
obj
=
cJSON_GetObjectItem
(
argJson
,
name
);
INIT_CHECK
(
obj
!=
NULL
,
return
SERVICE_FAILURE
);
int
ret
=
cJSON_IsArray
(
obj
);
INIT_ERROR_CHECK
(
ret
,
return
SERVICE_FAILURE
,
"Invalid type"
);
int
count
=
cJSON_GetArraySize
(
obj
);
int
tmpArray
[
count
];
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
obj
,
i
);
INIT_ERROR_CHECK
(
item
!=
NULL
,
return
SERVICE_FAILURE
,
"prase invalid"
);
tmpArray
[
i
]
=
(
int
)
cJSON_GetNumberValue
(
item
);
}
qsort
(
tmpArray
,
count
,
sizeof
(
int
),
Comparefunc
);
int
cpuCount
=
0
;
for
(
int
j
=
0
;
j
<
count
;
j
++
)
{
if
(
j
==
0
&&
tmpArray
[
0
]
==
0
)
{
tmpArray
[
cpuCount
++
]
=
0
;
continue
;
}
if
(
tmpArray
[
j
]
!=
tmpArray
[
j
-
1
])
{
tmpArray
[
cpuCount
++
]
=
tmpArray
[
j
];
}
}
args
->
cpus
=
(
int
*
)
malloc
(
cpuCount
*
sizeof
(
int
));
INIT_ERROR_CHECK
(
args
->
cpus
!=
NULL
,
return
SERVICE_FAILURE
,
"Failed to malloc for argv"
);
for
(
int
i
=
0
;
i
<
cpuCount
;
++
i
)
{
args
->
cpus
[
i
]
=
-
1
;
}
args
->
cpuNum
=
cpuCount
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
args
->
cpus
[
i
]
=
tmpArray
[
i
];
}
return
SERVICE_SUCCESS
;
}
int
ParseOneService
(
const
cJSON
*
curItem
,
Service
*
service
)
{
INIT_CHECK_RETURN_VALUE
(
curItem
!=
NULL
&&
service
!=
NULL
,
SERVICE_FAILURE
);
...
...
@@ -713,10 +659,8 @@ int ParseOneService(const cJSON *curItem, Service *service)
ret
=
GetServiceAttr
(
curItem
,
service
,
CONSOLE_STR_IN_CFG
,
SERVICE_ATTR_CONSOLE
,
NULL
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get console for service %s"
,
service
->
name
);
(
void
)
GetServiceArgs
(
curItem
,
"writepid"
,
MAX_WRITEPID_FILES
,
&
service
->
writePidArgs
);
(
void
)
GetServiceArgs
(
curItem
,
D_CAPS_STR_IN_CFG
,
MAX_WRITEPID_FILES
,
&
service
->
capsArgs
);
(
void
)
GetStringItem
(
curItem
,
APL_STR_IN_CFG
,
service
->
apl
,
MAX_APL_NAME
);
(
void
)
GetCpuArgs
(
curItem
,
CPU_CORE_STAR_IN_CFG
,
&
service
->
cpuInfo
);
ret
=
GetServiceArgs
(
curItem
,
"writepid"
,
MAX_WRITEPID_FILES
,
&
service
->
writePidArgs
);
INIT_CHECK_ONLY_ELOG
(
ret
==
0
,
"No writepid arg for service %s"
,
service
->
name
);
ret
=
GetServiceCaps
(
curItem
,
service
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get caps for service %s"
,
service
->
name
);
ret
=
GetDynamicService
(
curItem
,
service
);
...
...
test/unittest/BUILD.gn
浏览文件 @
670f0bab
...
...
@@ -179,7 +179,6 @@ ohos_unittest("init_ut") {
"STARTUP_INIT_TEST",
"PARAM_SUPPORT_SAVE_PERSIST",
"PARAM_SUPPORT_DAC",
"_GNU_SOURCE",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
...
...
test/unittest/common/BUILD.gn
浏览文件 @
670f0bab
...
...
@@ -22,10 +22,7 @@ if (defined(ohos_lite)) {
"-lpthread",
"-lm",
]
defines = [
"_GNU_SOURCE",
"OHOS_LITE",
]
defines = [ "OHOS_LITE" ]
if (storage_type == "emmc") {
defines += [ "USE_EMMC_STORAGE" ]
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录