feat(vfs): vfs支持FD_CLOEXEC标记

首先,POSIX规范规定文件描述符需要支持close-on-exec属性,修改前的vfs不支持close-on-exec,当exec系列函数执行时,进程所有的文件将会被关闭(0,1,2也重新被打开)。但是,系统有些时候是不能在exec时关闭全部文件的,例如在执行exec之前,就需要重定向进程的某些文件描述符时(使用dup2),就希望该文件不被关闭,继续保持重定向属性,shell执行进程并重定向其标准输出到文件,这是我们经常做的事情。

BREAKING CHANGE:
执行exec类函数后,进程拥有的文件描述符情况发生变化:修改前,默认关闭所有的进程文件描述符,0,1,2重新打开;修改后,除非文件描述符拥有FD_CLOEXEC标记,否则该描述符不会被关闭。

re #I3U81W

Change-Id: I54e841ac88e9835ec23e97de0cbc906c4e11f5a4
Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
This commit is contained in:
Guangyao Ma
2021-06-03 17:28:16 +08:00
parent 5edd78e756
commit 27dca4d857
24 changed files with 292 additions and 73 deletions

View File

@@ -39,6 +39,7 @@
#include "asm/page.h"
#ifdef LOSCFG_FS_VFS
#include "fs/fd_table.h"
#include "fs/fs_operation.h"
#endif
#include "time.h"
#include "user_copy.h"
@@ -290,7 +291,7 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
#ifdef LOSCFG_FS_VFS
if (OsProcessIsUserMode(processCB)) {
delete_files(processCB, processCB->files);
delete_files(processCB->files);
}
processCB->files = NULL;
#endif
@@ -1306,8 +1307,8 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
LOS_VmSpaceFree(oldSpace);
#ifdef LOSCFG_FS_VFS
delete_files(OsCurrProcessGet(), (struct files_struct *)oldFiles);
alloc_std_fd(OsCurrProcessGet()->files->fdt);
CloseOnExec((struct files_struct *)oldFiles);
delete_files_snapshot((struct files_struct *)oldFiles);
#endif
OsSwtmrRecycle(processCB->processID);