Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
be507218
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
460
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
be507218
编写于
2月 07, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 07, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1108 feat: 支持pid容器内访问进程挂载目录
Merge pull request !1108 from zhushengle/proc_pid_dir
上级
58610ea8
4e7d2edb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
149 addition
and
12 deletion
+149
-12
syscall/fs_syscall.c
syscall/fs_syscall.c
+139
-3
testsuites/unittest/container/full/It_pid_container_002.cpp
testsuites/unittest/container/full/It_pid_container_002.cpp
+10
-9
未找到文件。
syscall/fs_syscall.c
浏览文件 @
be507218
...
...
@@ -291,17 +291,135 @@ ssize_t SysWrite(int fd, const void *buf, size_t nbytes)
return
ret
;
}
// int vfs_normalize_path(const char *directory, const char *filename, char **pathname)
#ifdef LOSCFG_PID_CONTAINER
#ifdef LOSCFG_PROC_PROCESS_DIR
#define PROCESS_DIR_ROOT "/proc"
static
char
*
NextName
(
char
*
pos
,
uint8_t
*
len
)
{
char
*
name
=
NULL
;
while
(
*
pos
!=
0
&&
*
pos
==
'/'
)
{
pos
++
;
}
if
(
*
pos
==
'\0'
)
{
return
NULL
;
}
name
=
(
char
*
)
pos
;
while
(
*
pos
!=
'\0'
&&
*
pos
!=
'/'
)
{
pos
++
;
}
*
len
=
pos
-
name
;
return
name
;
}
static
unsigned
int
ProcRealProcessIDGet
(
unsigned
int
pid
)
{
unsigned
int
intSave
;
if
(
OS_PID_CHECK_INVALID
(
pid
))
{
return
0
;
}
SCHEDULER_LOCK
(
intSave
);
LosProcessCB
*
pcb
=
OsGetPCBFromVpid
(
pid
);
if
(
pcb
==
NULL
)
{
SCHEDULER_UNLOCK
(
intSave
);
return
0
;
}
int
rootPid
=
OsGetRootPid
(
pcb
);
SCHEDULER_UNLOCK
(
intSave
);
if
((
rootPid
==
OS_INVALID_VALUE
)
||
(
rootPid
==
pid
))
{
return
0
;
}
return
rootPid
;
}
static
int
ProcRealProcessDirGet
(
char
*
path
)
{
char
pidBuf
[
PATH_MAX
]
=
{
0
};
char
*
fullPath
=
NULL
;
uint8_t
strLen
=
0
;
int
pid
,
rootPid
;
int
ret
=
vfs_normalize_path
(
NULL
,
path
,
&
fullPath
);
if
(
ret
<
0
)
{
return
ret
;
}
int
procLen
=
strlen
(
PROCESS_DIR_ROOT
);
if
(
strncmp
(
fullPath
,
PROCESS_DIR_ROOT
,
procLen
)
!=
0
)
{
free
(
fullPath
);
return
0
;
}
char
*
pidStr
=
NextName
(
fullPath
+
procLen
,
&
strLen
);
if
(
pidStr
==
NULL
)
{
free
(
fullPath
);
return
0
;
}
if
((
*
pidStr
<=
'0'
)
||
(
*
pidStr
>
'9'
))
{
free
(
fullPath
);
return
0
;
}
if
(
memcpy_s
(
pidBuf
,
PATH_MAX
,
pidStr
,
strLen
)
!=
EOK
)
{
free
(
fullPath
);
return
0
;
}
pidBuf
[
strLen
]
=
'\0'
;
pid
=
atoi
(
pidBuf
);
if
(
pid
==
0
)
{
free
(
fullPath
);
return
0
;
}
rootPid
=
ProcRealProcessIDGet
((
unsigned
)
pid
);
if
(
rootPid
==
0
)
{
free
(
fullPath
);
return
0
;
}
if
(
snprintf_s
(
path
,
PATH_MAX
+
1
,
PATH_MAX
,
"/proc/%d%s"
,
rootPid
,
(
pidStr
+
strLen
))
<
0
)
{
free
(
fullPath
);
return
-
EFAULT
;
}
free
(
fullPath
);
return
0
;
}
#endif
#endif
static
int
GetPath
(
const
char
*
path
,
char
**
pathRet
)
{
int
ret
=
UserPathCopy
(
path
,
pathRet
);
if
(
ret
!=
0
)
{
return
ret
;
}
#ifdef LOSCFG_PID_CONTAINER
#ifdef LOSCFG_PROC_PROCESS_DIR
ret
=
ProcRealProcessDirGet
(
*
pathRet
);
if
(
ret
!=
0
)
{
return
ret
;
}
#endif
#endif
return
0
;
}
int
SysOpen
(
const
char
*
path
,
int
oflags
,
...)
{
int
ret
;
int
procFd
;
int
procFd
=
-
1
;
mode_t
mode
=
DEFAULT_FILE_MODE
;
/* 0666: File read-write properties. */
char
*
pathRet
=
NULL
;
if
(
path
!=
NULL
)
{
ret
=
UserPathCopy
(
path
,
&
pathRet
);
ret
=
GetPath
(
path
,
&
pathRet
);
if
(
ret
!=
0
)
{
return
ret
;
goto
ERROUT
;
}
}
...
...
@@ -432,6 +550,15 @@ ssize_t SysReadlink(const char *pathname, char *buf, size_t bufsize)
if
(
ret
!=
0
)
{
goto
OUT
;
}
#ifdef LOSCFG_PID_CONTAINER
#ifdef LOSCFG_PROC_PROCESS_DIR
ret
=
ProcRealProcessDirGet
(
pathRet
);
if
(
ret
!=
0
)
{
goto
OUT
;
}
#endif
#endif
}
if
(
!
LOS_IsUserAddressRange
((
vaddr_t
)(
UINTPTR
)
buf
,
bufsize
))
{
...
...
@@ -1840,6 +1967,15 @@ ssize_t SysReadlinkat(int dirfd, const char *pathname, char *buf, size_t bufsize
if
(
ret
!=
0
)
{
goto
OUT
;
}
#ifdef LOSCFG_PID_CONTAINER
#ifdef LOSCFG_PROC_PROCESS_DIR
ret
=
ProcRealProcessDirGet
(
pathRet
);
if
(
ret
!=
0
)
{
goto
OUT
;
}
#endif
#endif
}
if
(
dirfd
!=
AT_FDCWD
)
{
...
...
testsuites/unittest/container/full/It_pid_container_002.cpp
浏览文件 @
be507218
...
...
@@ -110,25 +110,26 @@ static int ChildFunClone1(void *p)
int
ret
;
pid_t
pid
=
getpid
();
int
childFunRet
=
(
int
)
pid
;
void
*
pstk
=
malloc
(
STACK_SIZE
);
if
(
pstk
==
NULL
)
{
return
EXIT_CODE_ERRNO_2
;
}
int
childPid
=
clone
(
ChildFunClone2
,
(
char
*
)
pstk
+
STACK_SIZE
,
CLONE_NEWPID
|
SIGCHLD
,
NULL
);
char
*
containerType
=
"pid"
;
int
childPid
=
clone
(
ChildFunClone2
,
NULL
,
CLONE_NEWPID
|
SIGCHLD
,
NULL
);
if
(
childPid
==
-
1
)
{
free
(
pstk
);
return
EXIT_CODE_ERRNO_3
;
}
auto
linkBuffer
=
ReadlinkContainer
(
childPid
,
containerType
);
auto
linkBuffer1
=
ReadlinkContainer
(
getpid
(),
containerType
);
ret
=
linkBuffer
.
compare
(
linkBuffer1
);
if
(
ret
==
0
)
{
(
void
)
waitpid
(
childPid
,
&
status
,
0
);
return
EXIT_CODE_ERRNO_5
;
}
ret
=
waitpid
(
childPid
,
&
status
,
0
);
ret
=
WIFEXITED
(
status
);
ret
=
WEXITSTATUS
(
status
);
if
(
ret
!=
CONTAINER_FIRST_PID
)
{
free
(
pstk
);
return
EXIT_CODE_ERRNO_4
;
}
free
(
pstk
);
return
childFunRet
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录