Provide richer error messages

Make sure most syscall/libc calls results are mapped to OsResult
that can produce more detailed error messages.
This commit is contained in:
topjohnwu
2025-04-14 18:05:14 -07:00
committed by John Wu
parent c1e061603b
commit 7bd901273c
13 changed files with 541 additions and 326 deletions
+2 -2
View File
@@ -130,7 +130,7 @@ impl MagiskInit {
null(),
)
}
.as_os_err()?;
.check_io_err()?;
self.mount_list.push("/proc".to_string());
}
if !path!("/sys/block").exists() {
@@ -144,7 +144,7 @@ impl MagiskInit {
null(),
)
}
.as_os_err()?;
.check_io_err()?;
self.mount_list.push("/sys".to_string());
}
+3 -3
View File
@@ -45,7 +45,7 @@ pub(crate) fn switch_root(path: &Utf8CStr) {
mounts.insert(info.target);
}
unsafe {
chdir(path.as_ptr()).as_os_err()?;
chdir(path.as_ptr()).check_io_err()?;
FsPath::from(path).move_mount_to(path!("/"))?;
chroot(raw_cstr!("."));
}
@@ -89,7 +89,7 @@ impl MagiskInit {
raw_cstr!("mode=755").cast(),
)
}
.as_os_err()
.check_io_err()
.log_ok();
path!("/init").copy_to(path!("/data/magiskinit")).log_ok();
@@ -108,7 +108,7 @@ impl MagiskInit {
}
unsafe {
execve(raw_cstr!("/init"), self.argv.cast(), environ.cast())
.as_os_err()
.check_io_err()
.log_ok();
exit(1);
}
+2 -2
View File
@@ -151,7 +151,7 @@ impl MagiskInit {
0,
ptr::null(),
)
.as_os_err()?;
.check_io_err()?;
}
}
@@ -174,7 +174,7 @@ impl MagiskInit {
}
// Create a new process waiting for init operations
let pid = unsafe { libc::fork().check_os_err()? };
let pid = unsafe { libc::fork() };
if pid != 0 {
return Ok(());
}