Fix poll misbehavior with negative pollfd value
This commit is contained in:
parent
d4b38f8ec0
commit
c05744b8d4
@ -20,14 +20,21 @@ pub fn do_poll_new(poll_fds: &[PollFd], mut timeout: Option<&mut Duration>) -> R
|
|||||||
|
|
||||||
// Map poll_fds to FileRef's
|
// Map poll_fds to FileRef's
|
||||||
let thread = current!();
|
let thread = current!();
|
||||||
|
let mut invalid_fd_count = 0;
|
||||||
let files: Vec<FileRef> = poll_fds
|
let files: Vec<FileRef> = poll_fds
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|poll_fd| {
|
.filter_map(|poll_fd| {
|
||||||
|
if (poll_fd.fd as i32) < 0 {
|
||||||
|
// If poll_fd is negative, ignore the events.
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let file = thread.file(poll_fd.fd).ok();
|
let file = thread.file(poll_fd.fd).ok();
|
||||||
|
|
||||||
// Mark an invalid fd by outputting an IoEvents::NVAL event
|
// Mark an invalid fd by outputting an IoEvents::NVAL event
|
||||||
if file.is_none() {
|
if file.is_none() {
|
||||||
poll_fd.revents.set(IoEvents::NVAL);
|
poll_fd.revents.set(IoEvents::NVAL);
|
||||||
|
invalid_fd_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
file
|
file
|
||||||
@ -35,9 +42,8 @@ pub fn do_poll_new(poll_fds: &[PollFd], mut timeout: Option<&mut Duration>) -> R
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// If there are any invalid fds, then report errors as events
|
// If there are any invalid fds, then report errors as events
|
||||||
let num_invalid_fds = poll_fds.len() - files.len();
|
if invalid_fd_count > 0 {
|
||||||
if num_invalid_fds > 0 {
|
return Ok(invalid_fd_count);
|
||||||
return Ok(num_invalid_fds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that all fds are valid, we set up a monitor for the set of files
|
// Now that all fds are valid, we set up a monitor for the set of files
|
||||||
@ -61,6 +67,7 @@ pub fn do_poll_new(poll_fds: &[PollFd], mut timeout: Option<&mut Duration>) -> R
|
|||||||
let events = file.poll_new() & mask;
|
let events = file.poll_new() & mask;
|
||||||
if !events.is_empty() {
|
if !events.is_empty() {
|
||||||
poll_fd.revents.set(events);
|
poll_fd.revents.set(events);
|
||||||
|
debug!("poll fd = {:?}, revents = {:?}", poll_fd, events);
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user