Skip to content

Commit 0533b88

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 0533b88

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/util_libc.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,16 @@ 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+
let err = last_os_error();
114+
// We should try again if the call was interrupted.
115+
if err.raw_os_error() != Some(libc::EINTR) {
116+
return Err(err);
117+
}
118+
} else {
119+
return Ok(fd);
120+
}
113121
}
114-
Ok(fd)
115122
}

0 commit comments

Comments
 (0)