mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-29 22:14:27 +02:00
Add log_ok()
for log().ok()
This commit is contained in:
parent
b1e17706a4
commit
9a74e19117
@ -55,6 +55,7 @@ impl<T> SilentResultExt<T> for Option<T> {
|
||||
pub trait ResultExt<T> {
|
||||
fn log(self) -> LoggedResult<T>;
|
||||
fn log_with_msg<F: FnOnce(Formatter) -> fmt::Result>(self, f: F) -> LoggedResult<T>;
|
||||
fn log_ok(self);
|
||||
}
|
||||
|
||||
// Internal C++ bridging logging routines
|
||||
@ -95,6 +96,17 @@ impl<T, R: Loggable<T>> ResultExt<T> for R {
|
||||
self.do_log(LogLevel::Error, Some(Location::caller()))
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
#[cfg(debug_assertions)]
|
||||
fn log_ok(self) {
|
||||
self.log().ok();
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn log_ok(self) {
|
||||
self.log().ok();
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn log_with_msg<F: FnOnce(Formatter) -> fmt::Result>(self, f: F) -> LoggedResult<T> {
|
||||
self.do_log_msg(LogLevel::Error, None, f)
|
||||
|
@ -109,7 +109,7 @@ impl MagiskD {
|
||||
let secure_dir = FsPath::from(cstr!(SECURE_DIR));
|
||||
if !secure_dir.exists() {
|
||||
if self.sdk_int < 24 {
|
||||
secure_dir.mkdir(0o700).log().ok();
|
||||
secure_dir.mkdir(0o700).log_ok();
|
||||
} else {
|
||||
error!("* {} is not present, abort", SECURE_DIR);
|
||||
return true;
|
||||
@ -137,7 +137,7 @@ impl MagiskD {
|
||||
info!("* Safe mode triggered");
|
||||
// Disable all modules and zygisk so next boot will be clean
|
||||
disable_modules();
|
||||
self.set_db_setting(DbEntryKey::ZygiskConfig, 0).log().ok();
|
||||
self.set_db_setting(DbEntryKey::ZygiskConfig, 0).log_ok();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -170,12 +170,12 @@ impl MagiskD {
|
||||
info!("** boot-complete triggered");
|
||||
|
||||
// Reset the bootloop counter once we have boot-complete
|
||||
self.set_db_setting(DbEntryKey::BootloopCount, 0).log().ok();
|
||||
self.set_db_setting(DbEntryKey::BootloopCount, 0).log_ok();
|
||||
|
||||
// At this point it's safe to create the folder
|
||||
let secure_dir = FsPath::from(cstr!(SECURE_DIR));
|
||||
if !secure_dir.exists() {
|
||||
secure_dir.mkdir(0o700).log().ok();
|
||||
secure_dir.mkdir(0o700).log_ok();
|
||||
}
|
||||
|
||||
self.ensure_manager();
|
||||
|
@ -314,7 +314,7 @@ impl MagiskD {
|
||||
out.push('=');
|
||||
out.push_str(values.get_text(i as i32));
|
||||
}
|
||||
writer.write_encodable(&out).log().ok();
|
||||
writer.write_encodable(&out).log_ok();
|
||||
};
|
||||
self.db_exec_with_rows(&sql, &[], &mut output_fn);
|
||||
writer.write_encodable("").log()
|
||||
|
@ -465,11 +465,11 @@ impl MagiskD {
|
||||
if let Ok(mut fd) = apk.open(O_RDONLY | O_CLOEXEC) {
|
||||
info.trusted_cert = read_certificate(&mut fd, MAGISK_VER_CODE);
|
||||
// Seek the fd back to start
|
||||
fd.seek(SeekFrom::Start(0)).log().ok();
|
||||
fd.seek(SeekFrom::Start(0)).log_ok();
|
||||
info.stub_apk_fd = Some(fd);
|
||||
}
|
||||
|
||||
apk.remove().log().ok();
|
||||
apk.remove().log_ok();
|
||||
}
|
||||
|
||||
pub fn get_manager_uid(&self, user: i32) -> i32 {
|
||||
|
@ -66,7 +66,7 @@ impl MagiskInit {
|
||||
let orig_init = FsPath::from(unsafe { Utf8CStr::from_ptr_unchecked(self.backup_init()) });
|
||||
|
||||
if orig_init.exists() {
|
||||
orig_init.rename_to(FsPath::from(cstr!("/init"))).log().ok();
|
||||
orig_init.rename_to(FsPath::from(cstr!("/init"))).log_ok();
|
||||
} else {
|
||||
// If the backup init is missing, this means that the boot ramdisk
|
||||
// was created from scratch, and the real init is in a separate CPIO,
|
||||
@ -151,7 +151,7 @@ pub unsafe extern "C" fn main(
|
||||
}
|
||||
|
||||
if getpid() == 1 {
|
||||
MagiskInit::new(argv).start().log().ok();
|
||||
MagiskInit::new(argv).start().log_ok();
|
||||
}
|
||||
|
||||
1
|
||||
|
@ -76,26 +76,20 @@ pub fn is_device_mounted(dev: u64, target: Pin<&mut CxxString>) -> bool {
|
||||
impl MagiskInit {
|
||||
pub(crate) fn prepare_data(&self) {
|
||||
debug!("Setup data tmp");
|
||||
fn inner() -> LoggedResult<()> {
|
||||
FsPath::from(cstr!("/data")).mkdir(0o755)?;
|
||||
unsafe {
|
||||
mount(
|
||||
raw_cstr!("magisk"),
|
||||
raw_cstr!("/data"),
|
||||
raw_cstr!("tmpfs"),
|
||||
0,
|
||||
raw_cstr!("mode=755").cast(),
|
||||
)
|
||||
}
|
||||
.as_os_err()?;
|
||||
FsPath::from(cstr!("/data")).mkdir(0o755).log_ok();
|
||||
unsafe {
|
||||
mount(
|
||||
raw_cstr!("magisk"),
|
||||
raw_cstr!("/data"),
|
||||
raw_cstr!("tmpfs"),
|
||||
0,
|
||||
raw_cstr!("mode=755").cast(),
|
||||
)
|
||||
}.as_os_err().log_ok();
|
||||
|
||||
FsPath::from(cstr!("/init")).copy_to(FsPath::from(cstr!("/data/magiskinit")))?;
|
||||
FsPath::from(cstr!("/.backup")).copy_to(FsPath::from(cstr!("/data/.backup")))?;
|
||||
FsPath::from(cstr!("/overlay.d")).copy_to(FsPath::from(cstr!("/data/overlay.d")))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
inner().ok();
|
||||
FsPath::from(cstr!("/init")).copy_to(FsPath::from(cstr!("/data/magiskinit"))).log_ok();
|
||||
FsPath::from(cstr!("/.backup")).copy_to(FsPath::from(cstr!("/data/.backup"))).log_ok();
|
||||
FsPath::from(cstr!("/overlay.d")).copy_to(FsPath::from(cstr!("/data/overlay.d"))).log_ok();
|
||||
}
|
||||
|
||||
pub(crate) fn exec_init(&self) {
|
||||
|
@ -116,14 +116,14 @@ impl MagiskInit {
|
||||
debug!("Patch @ {:#010X} [{}] -> [{}]", off, from, to);
|
||||
}
|
||||
if let Ok(mut dest) = dest.create(O_CREAT | O_WRONLY, 0) {
|
||||
dest.write_all(map.as_ref()).log().ok();
|
||||
dest.write_all(map.as_ref()).log_ok();
|
||||
} else {
|
||||
error!("Failed to create {}", dest);
|
||||
}
|
||||
} else {
|
||||
error!("Failed to open {} for hexpatch", src);
|
||||
}
|
||||
clone_attr(src, dest).log().ok();
|
||||
clone_attr(src, dest).log_ok();
|
||||
unsafe {
|
||||
mount(dest.as_ptr(), src.as_ptr(), null(), MS_BIND, null())
|
||||
.as_os_err()
|
||||
|
Loading…
x
Reference in New Issue
Block a user