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

@ -2,7 +2,7 @@
use super::{SyscallReturn, SYS_SOCKETPAIR};
use crate::{
fs::file_table::FileDescripter,
fs::file_table::{FdFlags, FileDescripter},
log_syscall_entry,
net::socket::unix::UnixStreamSocket,
prelude::*,
@ -37,9 +37,14 @@ pub fn sys_socketpair(domain: i32, type_: i32, protocol: i32, sv: Vaddr) -> Resu
let socket_fds = {
let current = current!();
let mut filetable = current.file_table().lock();
let fd_a = filetable.insert(socket_a);
let fd_b = filetable.insert(socket_b);
let mut file_table = current.file_table().lock();
let fd_flags = if sock_flags.contains(SockFlags::SOCK_CLOEXEC) {
FdFlags::CLOEXEC
} else {
FdFlags::empty()
};
let fd_a = file_table.insert(socket_a, fd_flags);
let fd_b = file_table.insert(socket_b, fd_flags);
SocketFds(fd_a, fd_b)
};