Support the close-on-exec file descriptor flag

This commit is contained in:
LI Qing
2023-12-13 11:29:03 +08:00
committed by Tate, Hongliang Tian
parent a6bb7c7bf5
commit 3de5c42afd
11 changed files with 153 additions and 48 deletions

View File

@ -7,7 +7,7 @@ use crate::{
events::IoEvents,
fs::{
epoll::{EpollCtl, EpollEvent, EpollFile, EpollFlags},
file_table::FileDescripter,
file_table::{FdFlags, FileDescripter},
utils::CreationFlags,
},
log_syscall_entry,
@ -26,13 +26,13 @@ pub fn sys_epoll_create1(flags: u32) -> Result<SyscallReturn> {
log_syscall_entry!(SYS_EPOLL_CREATE1);
debug!("flags = 0x{:x}", flags);
let close_on_exec = {
let fd_flags = {
let flags = CreationFlags::from_bits(flags)
.ok_or_else(|| Error::with_message(Errno::EINVAL, "invalid flags"))?;
if flags == CreationFlags::empty() {
false
FdFlags::empty()
} else if flags == CreationFlags::O_CLOEXEC {
true
FdFlags::CLOEXEC
} else {
// Only O_CLOEXEC is valid
return_errno_with_message!(Errno::EINVAL, "invalid flags");
@ -42,7 +42,7 @@ pub fn sys_epoll_create1(flags: u32) -> Result<SyscallReturn> {
let current = current!();
let epoll_file: Arc<EpollFile> = EpollFile::new();
let mut file_table = current.file_table().lock();
let fd = file_table.insert(epoll_file);
let fd = file_table.insert(epoll_file, fd_flags);
Ok(SyscallReturn::Return(fd as _))
}