Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
8dbdb977
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,发现更多精彩内容 >>
未验证
提交
8dbdb977
编写于
3月 28, 2023
作者:
许
许云通
提交者:
Gitee
3月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[revert]
Signed-off-by:
N
许云通
<
scorpion_xyt@outlook.com
>
上级
f072744b
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
74 addition
and
74 deletion
+74
-74
services/init/include/fd_holder_service.h
services/init/include/fd_holder_service.h
+1
-1
services/init/standard/fd_holder_service.c
services/init/standard/fd_holder_service.c
+15
-15
services/init/standard/init.c
services/init/standard/init.c
+48
-48
test/unittest/init/init_unittest.cpp
test/unittest/init/init_unittest.cpp
+10
-10
未找到文件。
services/init/include/fd_holder_service.h
浏览文件 @
8dbdb977
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
//
void RegisterFdHoldWatcher(int sock);
void
RegisterFdHoldWatcher
(
int
sock
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
services/init/standard/fd_holder_service.c
浏览文件 @
8dbdb977
...
@@ -166,18 +166,18 @@ void ProcessFdHoldEvent(const WatcherHandle taskHandle, int fd, uint32_t *events
...
@@ -166,18 +166,18 @@ void ProcessFdHoldEvent(const WatcherHandle taskHandle, int fd, uint32_t *events
*
events
=
Event_Read
;
*
events
=
Event_Read
;
}
}
//
void RegisterFdHoldWatcher(int sock)
void
RegisterFdHoldWatcher
(
int
sock
)
//
{
{
//
if (sock < 0) {
if
(
sock
<
0
)
{
//
INIT_LOGE("Invalid fd holder socket");
INIT_LOGE
(
"Invalid fd holder socket"
);
//
return;
return
;
//
}
}
//
WatcherHandle watcher = NULL;
WatcherHandle
watcher
=
NULL
;
//
LE_WatchInfo info = {};
LE_WatchInfo
info
=
{};
//
info.fd = sock;
info
.
fd
=
sock
;
//
info.flags = 0; // WATCHER_ONCE;
info
.
flags
=
0
;
// WATCHER_ONCE;
//
info.events = Event_Read;
info
.
events
=
Event_Read
;
//
info.processEvent = ProcessFdHoldEvent;
info
.
processEvent
=
ProcessFdHoldEvent
;
//
LE_StartWatcher(LE_GetDefaultLoop(), &watcher, &info, NULL);
LE_StartWatcher
(
LE_GetDefaultLoop
(),
&
watcher
,
&
info
,
NULL
);
//
}
}
services/init/standard/init.c
浏览文件 @
8dbdb977
...
@@ -46,50 +46,50 @@
...
@@ -46,50 +46,50 @@
#include "fd_holder_internal.h"
#include "fd_holder_internal.h"
#include "bootstage.h"
#include "bootstage.h"
//
static int FdHolderSockInit(void)
static
int
FdHolderSockInit
(
void
)
//
{
{
//
int sock = -1;
int
sock
=
-
1
;
//
int on = 1;
int
on
=
1
;
//
int fdHolderBufferSize = FD_HOLDER_BUFFER_SIZE; // 4KiB
int
fdHolderBufferSize
=
FD_HOLDER_BUFFER_SIZE
;
// 4KiB
//
sock = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
sock
=
socket
(
AF_UNIX
,
SOCK_DGRAM
|
SOCK_CLOEXEC
|
SOCK_NONBLOCK
,
0
);
//
if (sock < 0) {
if
(
sock
<
0
)
{
//
INIT_LOGE("Failed to create fd holder socket, err = %d", errno);
INIT_LOGE
(
"Failed to create fd holder socket, err = %d"
,
errno
);
//
return -1;
return
-
1
;
//
}
}
//
setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE, &fdHolderBufferSize, sizeof(fdHolderBufferSize));
setsockopt
(
sock
,
SOL_SOCKET
,
SO_RCVBUFFORCE
,
&
fdHolderBufferSize
,
sizeof
(
fdHolderBufferSize
));
//
setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
setsockopt
(
sock
,
SOL_SOCKET
,
SO_PASSCRED
,
&
on
,
sizeof
(
on
));
//
if (access(INIT_HOLDER_SOCKET_PATH, F_OK) == 0) {
if
(
access
(
INIT_HOLDER_SOCKET_PATH
,
F_OK
)
==
0
)
{
//
INIT_LOGI("%s exist, remove it", INIT_HOLDER_SOCKET_PATH);
INIT_LOGI
(
"%s exist, remove it"
,
INIT_HOLDER_SOCKET_PATH
);
//
unlink(INIT_HOLDER_SOCKET_PATH);
unlink
(
INIT_HOLDER_SOCKET_PATH
);
//
}
}
//
struct sockaddr_un addr;
struct
sockaddr_un
addr
;
//
addr.sun_family = AF_UNIX;
addr
.
sun_family
=
AF_UNIX
;
//
if (strncpy_s(addr.sun_path, sizeof(addr.sun_path),
if
(
strncpy_s
(
addr
.
sun_path
,
sizeof
(
addr
.
sun_path
),
//
INIT_HOLDER_SOCKET_PATH, strlen(INIT_HOLDER_SOCKET_PATH)) != 0) {
INIT_HOLDER_SOCKET_PATH
,
strlen
(
INIT_HOLDER_SOCKET_PATH
))
!=
0
)
{
//
INIT_LOGE("Failed to copy fd hoder socket path");
INIT_LOGE
(
"Failed to copy fd hoder socket path"
);
//
close(sock);
close
(
sock
);
//
return -1;
return
-
1
;
//
}
}
//
socklen_t len = (socklen_t)(offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path) + 1);
socklen_t
len
=
(
socklen_t
)(
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
strlen
(
addr
.
sun_path
)
+
1
);
//
if (bind(sock, (struct sockaddr *)&addr, len) < 0) {
if
(
bind
(
sock
,
(
struct
sockaddr
*
)
&
addr
,
len
)
<
0
)
{
//
INIT_LOGE("Failed to binder fd folder socket %d", errno);
INIT_LOGE
(
"Failed to binder fd folder socket %d"
,
errno
);
//
close(sock);
close
(
sock
);
//
return -1;
return
-
1
;
//
}
}
//
// Owned by root
// Owned by root
//
if (lchown(addr.sun_path, 0, 0)) {
if
(
lchown
(
addr
.
sun_path
,
0
,
0
))
{
//
INIT_LOGW("Failed to change owner of fd holder socket, err = %d", errno);
INIT_LOGW
(
"Failed to change owner of fd holder socket, err = %d"
,
errno
);
//
}
}
//
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
mode_t
mode
=
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IWGRP
|
S_IROTH
|
S_IWOTH
;
//
if (fchmodat(AT_FDCWD, addr.sun_path, mode, AT_SYMLINK_NOFOLLOW)) {
if
(
fchmodat
(
AT_FDCWD
,
addr
.
sun_path
,
mode
,
AT_SYMLINK_NOFOLLOW
))
{
//
INIT_LOGW("Failed to change mode of fd holder socket, err = %d", errno);
INIT_LOGW
(
"Failed to change mode of fd holder socket, err = %d"
,
errno
);
//
}
}
//
INIT_LOGI("Init fd holder socket done");
INIT_LOGI
(
"Init fd holder socket done"
);
//
return sock;
return
sock
;
//
}
}
void
SystemInit
(
void
)
void
SystemInit
(
void
)
{
{
...
@@ -101,10 +101,10 @@ void SystemInit(void)
...
@@ -101,10 +101,10 @@ void SystemInit(void)
// umask call always succeeds and return the previous mask value which is not needed here
// umask call always succeeds and return the previous mask value which is not needed here
(
void
)
umask
(
DEFAULT_UMASK_INIT
);
(
void
)
umask
(
DEFAULT_UMASK_INIT
);
MakeDirRecursive
(
"/dev/unix/socket"
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
|
S_IXOTH
);
MakeDirRecursive
(
"/dev/unix/socket"
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
|
S_IXOTH
);
//
int sock = FdHolderSockInit();
int
sock
=
FdHolderSockInit
();
//
if (sock >= 0) {
if
(
sock
>=
0
)
{
//
RegisterFdHoldWatcher(sock);
RegisterFdHoldWatcher
(
sock
);
//
}
}
InitControlFd
();
InitControlFd
();
}
}
...
...
test/unittest/init/init_unittest.cpp
浏览文件 @
8dbdb977
...
@@ -117,16 +117,16 @@ static void TestProcessTimer(const TimerHandle taskHandle, void *context)
...
@@ -117,16 +117,16 @@ static void TestProcessTimer(const TimerHandle taskHandle, void *context)
count
++
;
count
++
;
}
}
//
HWTEST_F(InitUnitTest, TestFdHoldService, TestSize.Level1)
HWTEST_F
(
InitUnitTest
,
TestFdHoldService
,
TestSize
.
Level1
)
//
{
{
//
RegisterFdHoldWatcher(-1);
RegisterFdHoldWatcher
(
-
1
);
//
TimerHandle timer = nullptr;
TimerHandle
timer
=
nullptr
;
//
int ret = LE_CreateTimer(LE_GetDefaultLoop(), &timer, TestProcessTimer, nullptr);
int
ret
=
LE_CreateTimer
(
LE_GetDefaultLoop
(),
&
timer
,
TestProcessTimer
,
nullptr
);
//
EXPECT_EQ(ret, 0);
EXPECT_EQ
(
ret
,
0
);
//
ret = LE_StartTimer(LE_GetDefaultLoop(), timer, 500, 2);
ret
=
LE_StartTimer
(
LE_GetDefaultLoop
(),
timer
,
500
,
2
);
//
EXPECT_EQ(ret, 0);
EXPECT_EQ
(
ret
,
0
);
//
SystemRun();
SystemRun
();
//
}
}
HWTEST_F
(
InitUnitTest
,
TestInitLog
,
TestSize
.
Level1
)
HWTEST_F
(
InitUnitTest
,
TestInitLog
,
TestSize
.
Level1
)
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录