Skip to content

Commit fcae1d2

Browse files
authored
libc: retry open when interrupted (#252)
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 d40ec2c commit fcae1d2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/util_libc.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,15 @@ cfg_if! {
113113
// SAFETY: path must be null terminated, FD must be manually closed.
114114
pub unsafe fn open_readonly(path: &str) -> Result<libc::c_int, Error> {
115115
debug_assert_eq!(path.as_bytes().last(), Some(&0));
116-
let fd = open(path.as_ptr() as *const _, libc::O_RDONLY | libc::O_CLOEXEC);
117-
if fd < 0 {
118-
return Err(last_os_error());
116+
loop {
117+
let fd = open(path.as_ptr() as *const _, libc::O_RDONLY | libc::O_CLOEXEC);
118+
if fd >= 0 {
119+
return Ok(fd);
120+
}
121+
let err = last_os_error();
122+
// We should try again if open() was interrupted.
123+
if err.raw_os_error() != Some(libc::EINTR) {
124+
return Err(err);
125+
}
119126
}
120-
Ok(fd)
121127
}

0 commit comments

Comments
 (0)