Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions kernel/src/ipc/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ impl FdTable {
return Err(9); // EBADF
}

// Per POSIX: if old_fd == new_fd, just verify old_fd is valid and return it
// This avoids a race condition where close_read/close_write followed by
// add_reader/add_writer would temporarily set the count to zero
if old_fd == new_fd {
// Verify old_fd is valid
if self.fds[old_fd as usize].is_none() {
return Err(9); // EBADF
}
return Ok(new_fd);
}

let fd_entry = self.fds[old_fd as usize].clone().ok_or(9)?;

// If new_fd is open, close it and decrement pipe ref counts
Expand Down
Loading