Skip to content

Commit

Permalink
Fix procfs read
Browse files Browse the repository at this point in the history
Summary: When reading from procfs or other kernel fs, kernel may not always fill up the provided buffer even if there are more content to read from, because kernel does not want to break up lines. As a result, reading with partially filled buffer does not mean that there is no more data to read from. Only reading with zero byte should indicate end of file.

Reviewed By: rikvanriel

Differential Revision: D66511187

fbshipit-source-id: 90035c0e8497351caede715d44e5370d69e5ab43
  • Loading branch information
lnyng authored and facebook-github-bot committed Nov 26, 2024
1 parent 4bb5cad commit 3fc645d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions below/common/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ pub fn read_kern_file_to_internal_buffer<R: Read>(
Ok(0) => break,
Ok(n) => {
total_read += n;
if n < BUFFER_CHUNK_SIZE {
break;
}
// n < BUFFER_CHUNK_SIZE does not indicate EOF because kernel
// may partially fill the buffer to avoid breaking the line.
}
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) => return Err(e),
Expand Down

0 comments on commit 3fc645d

Please sign in to comment.