Skip to content

Commit 2583185

Browse files
committed
libc: retry open when interrupted
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>
1 parent 157d6f2 commit 2583185

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/util_libc.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,15 @@ cfg_if! {
107107
// SAFETY: path must be null terminated, FD must be manually closed.
108108
pub unsafe fn open_readonly(path: &str) -> Result<libc::c_int, Error> {
109109
debug_assert_eq!(path.as_bytes().last(), Some(&0));
110-
let fd = open(path.as_ptr() as *const _, libc::O_RDONLY | libc::O_CLOEXEC);
111-
if fd < 0 {
112-
return Err(last_os_error());
110+
loop {
111+
let fd = open(path.as_ptr() as *const _, libc::O_RDONLY | libc::O_CLOEXEC);
112+
if fd >= 0 {
113+
return Ok(fd);
114+
}
115+
let err = last_os_error();
116+
// We should try again if open() was interrupted.
117+
if err.raw_os_error() != Some(libc::EINTR) {
118+
return Err(err);
119+
}
113120
}
114-
Ok(fd)
115121
}

0 commit comments

Comments
 (0)