Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
52e5af66
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
接近 2 年 前同步成功
通知
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看板
提交
52e5af66
编写于
1月 19, 2023
作者:
C
cheng_jinsong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix control_fd bugs
Signed-off-by:
N
cheng_jinsong
<
chengjinsong2@huawei.com
>
上级
6141a59c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
41 addition
and
16 deletion
+41
-16
interfaces/innerkits/control_fd/control_fd.h
interfaces/innerkits/control_fd/control_fd.h
+2
-1
interfaces/innerkits/control_fd/control_fd_client.c
interfaces/innerkits/control_fd/control_fd_client.c
+3
-0
interfaces/innerkits/control_fd/control_fd_service.c
interfaces/innerkits/control_fd/control_fd_service.c
+32
-11
services/init/standard/init_control_fd_service.c
services/init/standard/init_control_fd_service.c
+1
-1
test/fuzztest/CmdServiceInit_fuzzer/CmdServiceInit_fuzzer.cpp
.../fuzztest/CmdServiceInit_fuzzer/CmdServiceInit_fuzzer.cpp
+1
-1
test/unittest/innerkits/innerkits_unittest.cpp
test/unittest/innerkits/innerkits_unittest.cpp
+2
-2
未找到文件。
interfaces/innerkits/control_fd/control_fd.h
浏览文件 @
52e5af66
...
...
@@ -77,9 +77,10 @@ typedef struct {
char
cmd
[
0
];
}
CmdMessage
;
void
CmdServiceInit
(
const
char
*
socketPath
,
CallbackControlFdProcess
func
);
void
CmdServiceInit
(
const
char
*
socketPath
,
CallbackControlFdProcess
func
,
LoopHandle
loop
);
void
CmdClientInit
(
const
char
*
socketPath
,
uint16_t
type
,
const
char
*
cmd
);
void
CmdServiceProcessDelClient
(
pid_t
pid
);
void
CmdServiceProcessDestroyClient
(
void
);
#ifdef __cplusplus
#if __cplusplus
...
...
interfaces/innerkits/control_fd/control_fd_client.c
浏览文件 @
52e5af66
...
...
@@ -16,6 +16,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <termios.h>
#include <unistd.h>
...
...
@@ -167,6 +168,8 @@ CONTROL_FD_STATIC int InitPtyInterface(CmdAgent *agent, uint16_t type, const cha
ret
=
ptsname_r
(
pfd
,
ptsbuffer
,
sizeof
(
ptsbuffer
));
BEGET_ERROR_CHECK
(
ret
>=
0
,
close
(
pfd
);
return
-
1
,
"Failed to get pts name err=%d"
,
errno
);
BEGET_LOGI
(
"ptsbuffer is %s"
,
ptsbuffer
);
BEGET_ERROR_CHECK
(
chmod
(
ptsbuffer
,
S_IRWXU
|
S_IRGRP
|
S_IWGRP
|
S_IROTH
|
S_IWOTH
)
==
0
,
close
(
pfd
);
return
-
1
,
"Failed to chmod %s, err=%d"
,
ptsbuffer
,
errno
);
agent
->
ptyFd
=
pfd
;
LE_WatchInfo
info
=
{};
...
...
interfaces/innerkits/control_fd/control_fd_service.c
浏览文件 @
52e5af66
...
...
@@ -22,6 +22,7 @@
#include "securec.h"
static
CmdService
g_cmdService
;
static
LoopHandle
g_controlFdLoop
=
NULL
;
CallbackControlFdProcess
g_controlFdFunc
=
NULL
;
...
...
@@ -52,12 +53,12 @@ CONTROL_FD_STATIC void CmdOnRecvMessage(const TaskHandle task, const uint8_t *bu
if
(
agent
->
pid
==
0
)
{
OpenConsole
();
char
*
realPath
=
GetRealPath
(
msg
->
ptyName
);
BEGET_ERROR_CHECK
(
realPath
!=
NULL
,
return
,
"Failed get realpath, err=%d"
,
errno
);
BEGET_ERROR_CHECK
(
realPath
!=
NULL
,
_exit
(
1
)
,
"Failed get realpath, err=%d"
,
errno
);
char
*
strl
=
strstr
(
realPath
,
"/dev/pts"
);
BEGET_ERROR_CHECK
(
strl
!=
NULL
,
return
,
"pty slave
path %s is invaild"
,
realPath
);
BEGET_ERROR_CHECK
(
strl
!=
NULL
,
free
(
realPath
);
_exit
(
1
),
"pts
path %s is invaild"
,
realPath
);
int
fd
=
open
(
realPath
,
O_RDWR
);
free
(
realPath
);
BEGET_ERROR_CHECK
(
fd
>=
0
,
return
,
"Failed open %s, err=%d"
,
msg
->
ptyName
,
errno
);
BEGET_ERROR_CHECK
(
fd
>=
0
,
_exit
(
1
)
,
"Failed open %s, err=%d"
,
msg
->
ptyName
,
errno
);
(
void
)
dup2
(
fd
,
STDIN_FILENO
);
(
void
)
dup2
(
fd
,
STDOUT_FILENO
);
(
void
)
dup2
(
fd
,
STDERR_FILENO
);
// Redirect fd to 0, 1, 2
...
...
@@ -65,7 +66,7 @@ CONTROL_FD_STATIC void CmdOnRecvMessage(const TaskHandle task, const uint8_t *bu
if
(
g_controlFdFunc
!=
NULL
)
{
g_controlFdFunc
(
msg
->
type
,
msg
->
cmd
,
NULL
);
}
exit
(
0
);
_
exit
(
0
);
}
else
if
(
agent
->
pid
<
0
)
{
BEGET_LOGE
(
"[control_fd] Failed fork service"
);
}
...
...
@@ -85,7 +86,7 @@ CONTROL_FD_STATIC int SendMessage(LoopHandle loop, TaskHandle task, const char *
char
*
buff
=
(
char
*
)
LE_GetBufferInfo
(
handle
,
NULL
,
&
bufferSize
);
BEGET_ERROR_CHECK
(
buff
!=
NULL
,
return
-
1
,
"[control_fd] Failed get buffer info"
);
int
ret
=
memcpy_s
(
buff
,
bufferSize
,
message
,
strlen
(
message
)
+
1
);
BEGET_ERROR_CHECK
(
ret
==
0
,
LE_FreeBuffer
(
LE_GetDefaultLoop
()
,
task
,
handle
);
BEGET_ERROR_CHECK
(
ret
==
0
,
LE_FreeBuffer
(
g_controlFdLoop
,
task
,
handle
);
return
-
1
,
"[control_fd] Failed memcpy_s err=%d"
,
errno
);
LE_STATUS
status
=
LE_Send
(
loop
,
task
,
handle
,
strlen
(
message
)
+
1
);
BEGET_ERROR_CHECK
(
status
==
LE_SUCCESS
,
return
-
1
,
"[control_fd] Failed le send msg"
);
...
...
@@ -106,21 +107,21 @@ CONTROL_FD_STATIC int CmdOnIncommingConnect(const LoopHandle loop, const TaskHan
info
.
disConnectComplete
=
NULL
;
info
.
sendMessageComplete
=
NULL
;
info
.
recvMessage
=
CmdOnRecvMessage
;
int
ret
=
LE_AcceptStreamClient
(
LE_GetDefaultLoop
()
,
server
,
&
client
,
&
info
);
int
ret
=
LE_AcceptStreamClient
(
g_controlFdLoop
,
server
,
&
client
,
&
info
);
BEGET_ERROR_CHECK
(
ret
==
0
,
return
-
1
,
"[control_fd] Failed accept stream"
)
CmdTask
*
agent
=
(
CmdTask
*
)
LE_GetUserData
(
client
);
BEGET_ERROR_CHECK
(
agent
!=
NULL
,
return
-
1
,
"[control_fd] Invalid agent"
);
agent
->
task
=
client
;
OH_ListInit
(
&
agent
->
item
);
ret
=
SendMessage
(
LE_GetDefaultLoop
()
,
agent
->
task
,
"connect success."
);
ret
=
SendMessage
(
g_controlFdLoop
,
agent
->
task
,
"connect success."
);
BEGET_ERROR_CHECK
(
ret
==
0
,
return
-
1
,
"[control_fd] Failed send msg"
);
OH_ListAddTail
(
&
g_cmdService
.
head
,
&
agent
->
item
);
return
0
;
}
void
CmdServiceInit
(
const
char
*
socketPath
,
CallbackControlFdProcess
func
)
void
CmdServiceInit
(
const
char
*
socketPath
,
CallbackControlFdProcess
func
,
LoopHandle
loop
)
{
if
((
socketPath
==
NULL
)
||
(
func
==
NULL
))
{
if
((
socketPath
==
NULL
)
||
(
func
==
NULL
)
||
(
loop
==
NULL
)
)
{
BEGET_LOGE
(
"[control_fd] Invalid parameter"
);
return
;
}
...
...
@@ -135,7 +136,10 @@ void CmdServiceInit(const char *socketPath, CallbackControlFdProcess func)
info
.
sendMessageComplete
=
NULL
;
info
.
recvMessage
=
NULL
;
g_controlFdFunc
=
func
;
(
void
)
LE_CreateStreamServer
(
LE_GetDefaultLoop
(),
&
g_cmdService
.
serverTask
,
&
info
);
if
(
g_controlFdLoop
==
NULL
)
{
g_controlFdLoop
=
loop
;
}
(
void
)
LE_CreateStreamServer
(
g_controlFdLoop
,
&
g_cmdService
.
serverTask
,
&
info
);
}
static
int
ClientTraversalProc
(
ListNode
*
node
,
void
*
data
)
...
...
@@ -152,6 +156,23 @@ void CmdServiceProcessDelClient(pid_t pid)
CmdTask
*
agent
=
ListEntry
(
node
,
CmdTask
,
item
);
OH_ListRemove
(
&
agent
->
item
);
OH_ListInit
(
&
agent
->
item
);
LE_CloseTask
(
LE_GetDefaultLoop
(),
agent
->
task
);
LE_CloseTask
(
g_controlFdLoop
,
agent
->
task
);
}
}
static
void
CmdServiceDestroyProc
(
ListNode
*
node
)
{
if
(
node
==
NULL
)
{
return
;
}
CmdTask
*
agent
=
ListEntry
(
node
,
CmdTask
,
item
);
OH_ListRemove
(
&
agent
->
item
);
OH_ListInit
(
&
agent
->
item
);
LE_CloseTask
(
g_controlFdLoop
,
agent
->
task
);
}
void
CmdServiceProcessDestroyClient
(
void
)
{
OH_ListRemoveAll
(
&
g_cmdService
.
head
,
CmdServiceDestroyProc
);
LE_StopLoop
(
g_controlFdLoop
);
}
services/init/standard/init_control_fd_service.c
浏览文件 @
52e5af66
...
...
@@ -260,6 +260,6 @@ void ProcessControlFd(uint16_t type, const char *serviceCmd, const void *context
void
InitControlFd
(
void
)
{
CmdServiceInit
(
INIT_CONTROL_FD_SOCKET_PATH
,
ProcessControlFd
);
CmdServiceInit
(
INIT_CONTROL_FD_SOCKET_PATH
,
ProcessControlFd
,
LE_GetDefaultLoop
()
);
return
;
}
test/fuzztest/CmdServiceInit_fuzzer/CmdServiceInit_fuzzer.cpp
浏览文件 @
52e5af66
...
...
@@ -28,7 +28,7 @@ namespace OHOS {
{
std
::
string
str
(
reinterpret_cast
<
const
char
*>
(
data
),
size
);
CloseStdout
();
CmdServiceInit
(
str
.
c_str
(),
Func
);
CmdServiceInit
(
str
.
c_str
(),
Func
,
LE_GetDefaultLoop
()
);
return
true
;
}
}
...
...
test/unittest/innerkits/innerkits_unittest.cpp
浏览文件 @
52e5af66
...
...
@@ -354,12 +354,12 @@ HWTEST_F(InnerkitsUnitTest, TestControlFd, TestSize.Level1)
HWTEST_F
(
InnerkitsUnitTest
,
TestControlFdServer
,
TestSize
.
Level1
)
{
CmdServiceInit
(
nullptr
,
nullptr
);
CmdServiceInit
(
nullptr
,
nullptr
,
nullptr
);
CmdServiceInit
(
"/data/testSock1"
,
[](
uint16_t
type
,
const
char
*
serviceCmd
,
const
void
*
context
)
{
UNUSED
(
type
);
UNUSED
(
serviceCmd
);
UNUSED
(
context
);
});
}
,
LE_GetDefaultLoop
()
);
TaskHandle
testServer
;
LE_StreamServerInfo
info
=
{};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录