relibc: fix mutex_owner_id_is_live Sys::open/close return type
Sys::open returns Result<i32, Errno> (not i32), and Sys::close returns Result<i32, Errno> as well. The previous version of mutex_owner_id_is_live used the cstr.as_ptr() pattern (which the cross-compile correctly rejected because Sys::open expects NulStr<'_, Thin> not *const c_char) and treated the Result as a raw fd (which the type system rejected). Fix: pass the CStr directly (it converts to NulStr via Deref) and match on the Result<>'s Ok/Err variants instead of doing fd >= 0 comparison on a non-i32 type.
This commit is contained in:
+8
-7
@@ -481,17 +481,18 @@ pub fn mutex_owner_id_is_live(owner: u32) -> bool {
|
||||
// For Redox, attempt to open the thread's "name" handle via
|
||||
// the proc scheme. If the thread is alive, the open succeeds;
|
||||
// if it has exited and been reaped, the open returns ENOENT.
|
||||
let path = format!("proc:{}/name", owner);
|
||||
let path = alloc::format!("proc:{}/name\0", owner);
|
||||
let cstr = match crate::c_str::CStr::from_bytes_with_nul(path.as_bytes()) {
|
||||
Ok(c) => c,
|
||||
Err(_) => return false,
|
||||
};
|
||||
let fd = crate::platform::Sys::open(cstr.as_ptr(), crate::header::fcntl::O_RDONLY, 0);
|
||||
if fd >= 0 {
|
||||
let _ = crate::platform::Sys::close(fd);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
let fd = crate::platform::Sys::open(cstr, crate::header::fcntl::O_RDONLY, 0);
|
||||
match fd {
|
||||
Ok(fd) => {
|
||||
let _ = crate::platform::Sys::close(fd);
|
||||
true
|
||||
}
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
|
||||
Reference in New Issue
Block a user