Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
ee4cf831
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看板
提交
ee4cf831
编写于
6月 23, 2021
作者:
O
openharmony_ci
提交者:
Gitee
6月 23, 2021
浏览文件
操作
浏览文件
下载
差异文件
!345 add /proc/fd file to dump pid/fd information
Merge pull request !345 from LeonChan/proc_fd
上级
702d8d9d
600dded3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
201 addition
and
0 deletion
+201
-0
fs/proc/include/internal.h
fs/proc/include/internal.h
+2
-0
fs/proc/os_adapt/fd_proc.c
fs/proc/os_adapt/fd_proc.c
+142
-0
fs/proc/os_adapt/proc_init.c
fs/proc/os_adapt/proc_init.c
+1
-0
kernel/base/core/los_process.c
kernel/base/core/los_process.c
+46
-0
kernel/include/los_process.h
kernel/include/los_process.h
+10
-0
未找到文件。
fs/proc/include/internal.h
浏览文件 @
ee4cf831
...
...
@@ -65,6 +65,8 @@ extern void ProcUptimeInit(void);
extern
void
ProcFsCacheInit
(
void
);
extern
void
ProcFdInit
(
void
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
fs/proc/os_adapt/fd_proc.c
0 → 100644
浏览文件 @
ee4cf831
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "proc_fs.h"
#include <stdbool.h>
#include "fs/file.h"
#include "vfs_config.h"
#include "internal.h"
#include "fs/fd_table.h"
#include "los_process.h"
#include "capability_api.h"
#include "capability_type.h"
/*
* Template: Pid Fd [SysFd ] Name
*/
static
void
FillFdInfo
(
struct
SeqBuf
*
seqBuf
,
struct
filelist
*
fileList
,
unsigned
int
pid
,
bool
hasPrivilege
)
{
int
fd
;
int
sysFd
;
char
*
name
=
NULL
;
struct
file
*
filp
=
NULL
;
struct
fd_table_s
*
fdt
=
LOS_GetFdTable
(
pid
);
if
((
fdt
==
NULL
)
||
(
fdt
->
proc_fds
==
NULL
))
{
return
;
}
(
void
)
sem_wait
(
&
fdt
->
ft_sem
);
for
(
fd
=
MIN_START_FD
;
fd
<
fdt
->
max_fds
;
fd
++
)
{
if
(
FD_ISSET
(
fd
,
fdt
->
proc_fds
))
{
sysFd
=
fdt
->
ft_fds
[
fd
].
sysFd
;
if
(
sysFd
<
CONFIG_NFILE_DESCRIPTORS
)
{
filp
=
&
fileList
->
fl_files
[
sysFd
];
name
=
filp
->
f_path
;
}
else
if
(
sysFd
<
(
CONFIG_NFILE_DESCRIPTORS
+
CONFIG_NSOCKET_DESCRIPTORS
))
{
name
=
"(socks)"
;
}
else
if
(
sysFd
<
(
FD_SETSIZE
+
CONFIG_NTIME_DESCRIPTORS
))
{
name
=
"(timer)"
;
}
else
if
(
sysFd
<
(
MQUEUE_FD_OFFSET
+
CONFIG_NQUEUE_DESCRIPTORS
))
{
name
=
"(mqueue)"
;
}
else
{
name
=
"(unknown)"
;
}
if
(
hasPrivilege
)
{
(
void
)
LosBufPrintf
(
seqBuf
,
"%u
\t
%d
\t
%d
\t
%s
\n
"
,
pid
,
fd
,
sysFd
,
name
);
}
else
{
(
void
)
LosBufPrintf
(
seqBuf
,
"%u
\t
%d
\t
%s
\n
"
,
pid
,
fd
,
name
);
}
}
}
(
void
)
sem_post
(
&
fdt
->
ft_sem
);
}
static
int
FdProcFill
(
struct
SeqBuf
*
seqBuf
,
void
*
v
)
{
int
pidNum
;
bool
hasPrivilege
;
unsigned
int
pidMaxNum
;
unsigned
int
*
pidList
=
NULL
;
/* privilege user */
if
(
IsCapPermit
(
CAP_DAC_READ_SEARCH
))
{
pidMaxNum
=
LOS_GetSystemProcessMaximum
();
pidList
=
(
unsigned
int
*
)
malloc
(
pidMaxNum
*
sizeof
(
unsigned
int
));
if
(
pidList
==
NULL
)
{
return
-
ENOMEM
;
}
pidNum
=
LOS_GetUsedPIDList
(
pidList
,
pidMaxNum
);
hasPrivilege
=
true
;
(
void
)
LosBufPrintf
(
seqBuf
,
"Pid
\t
Fd
\t
SysFd
\t
Name
\n
"
);
}
else
{
pidNum
=
1
;
pidList
=
(
unsigned
int
*
)
malloc
(
pidNum
*
sizeof
(
unsigned
int
));
if
(
pidList
==
NULL
)
{
return
-
ENOMEM
;
}
pidList
[
0
]
=
LOS_GetCurrProcessID
();
hasPrivilege
=
false
;
(
void
)
LosBufPrintf
(
seqBuf
,
"Pid
\t
Fd
\t
Name
\n
"
);
}
struct
filelist
*
fileList
=
&
tg_filelist
;
(
void
)
sem_wait
(
&
fileList
->
fl_sem
);
for
(
int
i
=
0
;
i
<
pidNum
;
i
++
)
{
FillFdInfo
(
seqBuf
,
fileList
,
pidList
[
i
],
hasPrivilege
);
}
free
(
pidList
);
(
void
)
sem_post
(
&
fileList
->
fl_sem
);
return
0
;
}
static
const
struct
ProcFileOperations
FD_PROC_FOPS
=
{
.
read
=
FdProcFill
,
};
void
ProcFdInit
(
void
)
{
struct
ProcDirEntry
*
pde
=
CreateProcEntry
(
"fd"
,
0
,
NULL
);
if
(
pde
==
NULL
)
{
PRINT_ERR
(
"creat /proc/fd error.
\n
"
);
return
;
}
pde
->
procFileOps
=
&
FD_PROC_FOPS
;
}
fs/proc/os_adapt/proc_init.c
浏览文件 @
ee4cf831
...
...
@@ -65,6 +65,7 @@ void ProcFsInit(void)
ProcUptimeInit
();
ProcKernelTraceInit
();
ProcFsCacheInit
();
ProcFdInit
();
}
LOS_MODULE_INIT
(
ProcFsInit
,
LOS_INIT_LEVEL_KMOD_EXTENDED
);
...
...
kernel/base/core/los_process.c
浏览文件 @
ee4cf831
...
...
@@ -1794,6 +1794,52 @@ LITE_OS_SEC_TEXT VOID LOS_Exit(INT32 status)
OsProcessExit
(
OsCurrTaskGet
(),
(
UINT32
)
status
);
}
LITE_OS_SEC_TEXT
INT32
LOS_GetUsedPIDList
(
UINT32
*
pidList
,
INT32
pidMaxNum
)
{
LosProcessCB
*
pcb
=
NULL
;
INT32
num
=
0
;
UINT32
intSave
;
UINT32
pid
=
1
;
if
(
pidList
==
NULL
)
{
return
0
;
}
SCHEDULER_LOCK
(
intSave
);
while
(
OsProcessIDUserCheckInvalid
(
pid
)
==
false
)
{
pcb
=
OS_PCB_FROM_PID
(
pid
);
pid
++
;
if
(
OsProcessIsUnused
(
pcb
))
{
continue
;
}
pidList
[
num
]
=
pcb
->
processID
;
num
++
;
if
(
num
>=
pidMaxNum
)
{
break
;
}
}
SCHEDULER_UNLOCK
(
intSave
);
return
num
;
}
#ifdef LOSCFG_FS_VFS
LITE_OS_SEC_TEXT
struct
fd_table_s
*
LOS_GetFdTable
(
UINT32
pid
)
{
LosProcessCB
*
pcb
=
NULL
;
struct
files_struct
*
files
=
NULL
;
if
(
OS_PID_CHECK_INVALID
(
pid
))
{
return
NULL
;
}
pcb
=
OS_PCB_FROM_PID
(
pid
);
files
=
pcb
->
files
;
if
(
files
==
NULL
)
{
return
NULL
;
}
return
files
->
fdt
;
}
#endif
LITE_OS_SEC_TEXT
UINT32
LOS_GetCurrProcessID
(
VOID
)
{
return
OsCurrProcessGet
()
->
processID
;
...
...
kernel/include/los_process.h
浏览文件 @
ee4cf831
...
...
@@ -34,6 +34,10 @@
#include "los_task.h"
#ifdef LOSCFG_FS_VFS
#include "fs/fd_table.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern
"C"
{
...
...
@@ -68,6 +72,12 @@ extern BOOL LOS_CheckInGroups(UINT32 gid);
extern
INT32
LOS_GetUserID
(
VOID
);
extern
INT32
LOS_GetGroupID
(
VOID
);
extern
INT32
LOS_GetUsedPIDList
(
UINT32
*
pidList
,
INT32
pidMaxNum
);
#ifdef LOSCFG_FS_VFS
struct
fd_table_s
*
LOS_GetFdTable
(
UINT32
pid
);
#endif
#ifdef __cplusplus
#if __cplusplus
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录