Skip to content

Commit

Permalink
libc: retry open when interrupted (#252)
Browse files Browse the repository at this point in the history
The open call can be interrupted. Since sys_fill_exact covers this for
read operation already, it should be done here as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
  • Loading branch information
stoeckmann authored Mar 25, 2022
1 parent d40ec2c commit fcae1d2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/util_libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ cfg_if! {
// SAFETY: path must be null terminated, FD must be manually closed.
pub unsafe fn open_readonly(path: &str) -> Result<libc::c_int, Error> {
debug_assert_eq!(path.as_bytes().last(), Some(&0));
let fd = open(path.as_ptr() as *const _, libc::O_RDONLY | libc::O_CLOEXEC);
if fd < 0 {
return Err(last_os_error());
loop {
let fd = open(path.as_ptr() as *const _, libc::O_RDONLY | libc::O_CLOEXEC);
if fd >= 0 {
return Ok(fd);
}
let err = last_os_error();
// We should try again if open() was interrupted.
if err.raw_os_error() != Some(libc::EINTR) {
return Err(err);
}
}
Ok(fd)
}

0 comments on commit fcae1d2

Please sign in to comment.