From 49eef0c094650c2e49ffc5ff736e7bef51cfaa4e Mon Sep 17 00:00:00 2001 From: Jianfeng Jiang Date: Thu, 18 Jul 2024 08:45:15 +0000 Subject: [PATCH] Select should not return ETIME --- kernel/aster-nix/src/syscall/select.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kernel/aster-nix/src/syscall/select.rs b/kernel/aster-nix/src/syscall/select.rs index 1ec184f78..fab677831 100644 --- a/kernel/aster-nix/src/syscall/select.rs +++ b/kernel/aster-nix/src/syscall/select.rs @@ -52,13 +52,26 @@ pub fn sys_select( nfds, readfds, writefds, exceptfds, timeout ); - let num_revents = do_select( + let num_revents = match do_select( nfds, readfds.as_mut(), writefds.as_mut(), exceptfds.as_mut(), timeout, - )?; + ) { + Ok(num_revents) => num_revents, + Err(e) if e.error() == Errno::ETIME => { + // The return value is zero if the timeout expires + // before any file descriptors became ready + return Ok(SyscallReturn::Return(0)); + } + Err(e) => return Err(e), + }; + + // FIXME: The Linux select() and pselect6() system call + // modifies its timeout argument to reflect the amount of time not slept. + // However, the glibc wrapper function hides this behavior. + // Maybe we should follow the Linux behavior. let set_fdset = |fdset_addr: Vaddr, fdset: Option| -> Result<()> { if let Some(fdset) = fdset {