Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
c06cd358
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看板
提交
c06cd358
编写于
6月 01, 2022
作者:
M
Mupceet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix dump_service bug
Signed-off-by:
N
Mupceet
<
laiguizhong@huawei.com
>
上级
0e7cfe2d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
28 deletion
+32
-28
interfaces/innerkits/control_fd/control_fd.h
interfaces/innerkits/control_fd/control_fd.h
+1
-0
interfaces/innerkits/control_fd/control_fd_client.c
interfaces/innerkits/control_fd/control_fd_client.c
+17
-13
interfaces/innerkits/control_fd/control_fd_service.c
interfaces/innerkits/control_fd/control_fd_service.c
+14
-15
未找到文件。
interfaces/innerkits/control_fd/control_fd.h
浏览文件 @
c06cd358
...
...
@@ -61,6 +61,7 @@ typedef struct {
void
CmdServiceInit
(
const
char
*
socketPath
,
CallbackControlFdProcess
func
);
void
CmdClientInit
(
const
char
*
socketPath
,
uint16_t
type
,
const
char
*
cmd
,
const
char
*
fifoName
);
void
DestroyCmdFifo
(
int
rfd
,
int
wfd
,
const
char
*
readPath
,
const
char
*
writePath
);
#ifdef __cplusplus
#if __cplusplus
...
...
interfaces/innerkits/control_fd/control_fd_client.c
浏览文件 @
c06cd358
...
...
@@ -70,6 +70,9 @@ static void ProcessFifoRead(const WatcherHandle taskHandle, int fd, uint32_t *ev
int
readlen
=
read
(
fd
,
buf
,
FIFO_BUF_SIZE
-
1
);
if
(
readlen
>
0
)
{
fprintf
(
stdout
,
"%s"
,
buf
);
}
else
{
DestroyCmdFifo
(
g_FifoReadFd
,
g_FifoWriteFd
,
g_FifoReadPath
,
g_FifoWritePath
);
return
;
}
int
ret
=
fflush
(
stdout
);
BEGET_ERROR_CHECK
(
ret
==
0
,
return
,
"[control_fd] Failed fflush err=%d"
,
errno
);
...
...
@@ -79,20 +82,21 @@ static void ProcessFifoRead(const WatcherHandle taskHandle, int fd, uint32_t *ev
*
events
=
Event_Read
;
}
static
void
DestroyCmdFifo
(
void
)
void
DestroyCmdFifo
(
int
rfd
,
int
wfd
,
const
char
*
readPath
,
const
char
*
writePath
)
{
if
(
g_FifoReadFd
>=
0
)
{
(
void
)
close
(
g_FifoReadFd
);
if
(
rfd
>=
0
)
{
(
void
)
close
(
rfd
);
}
if
(
wfd
>=
0
)
{
(
void
)
close
(
wfd
);
}
if
(
readPath
!=
NULL
)
{
BEGET_CHECK_ONLY_ELOG
(
unlink
(
readPath
)
==
0
,
"Failed unlink fifo %s"
,
readPath
);
}
if
(
g_FifoWriteFd
>=
0
)
{
(
void
)
close
(
g_FifoWriteFd
);
if
(
writePath
!=
NULL
)
{
BEGET_CHECK_ONLY_ELOG
(
unlink
(
writePath
)
==
0
,
"Failed unlink fifo %s"
,
writePath
);
}
g_FifoReadFd
=
-
1
;
g_FifoWriteFd
=
-
1
;
int
ret
=
unlink
(
g_FifoReadPath
);
BEGET_CHECK_ONLY_ELOG
(
ret
==
0
,
"Failed unlink fifo %s"
,
g_FifoReadPath
);
ret
=
unlink
(
g_FifoWritePath
);
BEGET_CHECK_ONLY_ELOG
(
ret
==
0
,
"Failed unlink fifo %s"
,
g_FifoReadPath
);
}
static
void
CmdOnRecvMessage
(
const
TaskHandle
task
,
const
uint8_t
*
buffer
,
uint32_t
buffLen
)
...
...
@@ -108,7 +112,7 @@ static void CmdOnConntectComplete(const TaskHandle client)
static
void
CmdOnClose
(
const
TaskHandle
task
)
{
BEGET_LOGI
(
"[control_fd] CmdOnClose"
);
DestroyCmdFifo
();
DestroyCmdFifo
(
g_FifoReadFd
,
g_FifoWriteFd
,
g_FifoReadPath
,
g_FifoWritePath
);
}
static
void
CmdDisConnectComplete
(
const
TaskHandle
client
)
...
...
@@ -270,5 +274,5 @@ void CmdClientInit(const char *socketPath, uint16_t type, const char *cmd, const
BEGET_LOGI
(
"Cmd Client exit "
);
LE_CloseStreamTask
(
LE_GetDefaultLoop
(),
agent
->
task
);
free
(
agent
);
DestroyCmdFifo
();
DestroyCmdFifo
(
g_FifoReadFd
,
g_FifoWriteFd
,
g_FifoReadPath
,
g_FifoWritePath
);
}
interfaces/innerkits/control_fd/control_fd_service.c
浏览文件 @
c06cd358
...
...
@@ -41,24 +41,15 @@ static void CmdOnSendMessageComplete(const TaskHandle task, const BufferHandle h
BEGET_LOGI
(
"[control_fd] CmdOnSendMessageComplete "
);
}
static
int
OpenFifo
(
int
pid
,
bool
read
,
const
char
*
pipeName
)
static
int
OpenFifo
(
bool
read
,
const
char
*
pipePath
)
{
// create pipe for cmd
if
(
pipe
Name
==
NULL
)
{
if
(
pipe
Path
==
NULL
)
{
return
-
1
;
}
char
buffer
[
FIFO_PATH_SIZE
]
=
{
0
};
int
ret
=
0
;
if
(
read
==
true
)
{
ret
=
sprintf_s
(
buffer
,
sizeof
(
buffer
)
-
1
,
"/dev/fifo/%s1.%d"
,
pipeName
,
pid
);
BEGET_ERROR_CHECK
(
ret
>
0
,
return
-
1
,
"[control_fd] Failed sprintf_s err=%d"
,
errno
);
}
else
{
ret
=
sprintf_s
(
buffer
,
sizeof
(
buffer
)
-
1
,
"/dev/fifo/%s0.%d"
,
pipeName
,
pid
);
BEGET_ERROR_CHECK
(
ret
>
0
,
return
-
1
,
"[control_fd] Failed sprintf_s err=%d"
,
errno
);
}
int
flags
=
read
?
(
O_RDONLY
|
O_TRUNC
|
O_NONBLOCK
)
:
(
O_WRONLY
|
O_TRUNC
);
return
open
(
buffer
,
flags
);
return
open
(
pipePath
,
flags
);
}
static
void
CmdOnRecvMessage
(
const
TaskHandle
task
,
const
uint8_t
*
buffer
,
uint32_t
buffLen
)
...
...
@@ -73,11 +64,16 @@ static void CmdOnRecvMessage(const TaskHandle task, const uint8_t *buffer, uint3
BEGET_LOGE
(
"[control_fd] Failed msg "
);
return
;
}
int
reader
=
OpenFifo
(
msg
->
pid
,
true
,
msg
->
fifoName
);
// read
char
readPath
[
FIFO_PATH_SIZE
]
=
{
0
};
int
ret
=
sprintf_s
(
readPath
,
sizeof
(
readPath
)
-
1
,
"/dev/fifo/%s1.%d"
,
msg
->
fifoName
,
msg
->
pid
);
BEGET_ERROR_CHECK
(
ret
>
0
,
return
,
"[control_fd] Failed sprintf_s err=%d"
,
errno
);
int
reader
=
OpenFifo
(
true
,
readPath
);
// read
BEGET_ERROR_CHECK
(
reader
>
0
,
return
,
"[control_fd] Failed to open filo"
);
int
writer
=
OpenFifo
(
msg
->
pid
,
false
,
msg
->
fifoName
);
// write
char
writePath
[
FIFO_PATH_SIZE
]
=
{
0
};
ret
=
sprintf_s
(
writePath
,
sizeof
(
writePath
)
-
1
,
"/dev/fifo/%s0.%d"
,
msg
->
fifoName
,
msg
->
pid
);
BEGET_ERROR_CHECK
(
ret
>
0
,
return
,
"[control_fd] Failed sprintf_s err=%d"
,
errno
);
int
writer
=
OpenFifo
(
false
,
writePath
);
// write
BEGET_ERROR_CHECK
(
writer
>
0
,
return
,
"[control_fd] Failed to open filo"
);
pid_t
pid
=
fork
();
...
...
@@ -85,11 +81,14 @@ static void CmdOnRecvMessage(const TaskHandle task, const uint8_t *buffer, uint3
(
void
)
dup2
(
reader
,
STDIN_FILENO
);
(
void
)
dup2
(
writer
,
STDOUT_FILENO
);
(
void
)
dup2
(
writer
,
STDERR_FILENO
);
// Redirect fd to 0, 1, 2
(
void
)
close
(
reader
);
(
void
)
close
(
writer
);
g_controlFdFunc
(
msg
->
type
,
msg
->
cmd
,
NULL
);
exit
(
0
);
}
else
if
(
pid
<
0
)
{
BEGET_LOGE
(
"[control_fd] Failed fork service"
);
}
DestroyCmdFifo
(
reader
,
writer
,
readPath
,
writePath
);
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录