Skip to content

Commit a9045f7

Browse files
committed
Add log_ok() for log().ok()
1 parent e92420d commit a9045f7

File tree

7 files changed

+31
-30
lines changed

7 files changed

+31
-30
lines changed

native/src/base/result.rs

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl<T> SilentResultExt<T> for Option<T> {
5555
pub trait ResultExt<T> {
5656
fn log(self) -> LoggedResult<T>;
5757
fn log_with_msg<F: FnOnce(Formatter) -> fmt::Result>(self, f: F) -> LoggedResult<T>;
58+
fn log_ok(self);
5859
}
5960

6061
// Internal C++ bridging logging routines
@@ -95,6 +96,12 @@ impl<T, R: Loggable<T>> ResultExt<T> for R {
9596
self.do_log(LogLevel::Error, Some(Location::caller()))
9697
}
9798

99+
#[track_caller]
100+
#[cfg(debug_assertions)]
101+
fn log_ok(self) {
102+
self.log().ok();
103+
}
104+
98105
#[cfg(not(debug_assertions))]
99106
fn log_with_msg<F: FnOnce(Formatter) -> fmt::Result>(self, f: F) -> LoggedResult<T> {
100107
self.do_log_msg(LogLevel::Error, None, f)

native/src/core/daemon.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl MagiskD {
109109
let secure_dir = FsPath::from(cstr!(SECURE_DIR));
110110
if !secure_dir.exists() {
111111
if self.sdk_int < 24 {
112-
secure_dir.mkdir(0o700).log().ok();
112+
secure_dir.mkdir(0o700).log_ok();
113113
} else {
114114
error!("* {} is not present, abort", SECURE_DIR);
115115
return true;
@@ -137,7 +137,7 @@ impl MagiskD {
137137
info!("* Safe mode triggered");
138138
// Disable all modules and zygisk so next boot will be clean
139139
disable_modules();
140-
self.set_db_setting(DbEntryKey::ZygiskConfig, 0).log().ok();
140+
self.set_db_setting(DbEntryKey::ZygiskConfig, 0).log_ok();
141141
return true;
142142
}
143143

@@ -169,12 +169,12 @@ impl MagiskD {
169169
info!("** boot-complete triggered");
170170

171171
// Reset the bootloop counter once we have boot-complete
172-
self.set_db_setting(DbEntryKey::BootloopCount, 0).log().ok();
172+
self.set_db_setting(DbEntryKey::BootloopCount, 0).log_ok();
173173

174174
// At this point it's safe to create the folder
175175
let secure_dir = FsPath::from(cstr!(SECURE_DIR));
176176
if !secure_dir.exists() {
177-
secure_dir.mkdir(0o700).log().ok();
177+
secure_dir.mkdir(0o700).log_ok();
178178
}
179179

180180
self.ensure_manager();

native/src/core/db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl MagiskD {
314314
out.push('=');
315315
out.push_str(values.get_text(i as i32));
316316
}
317-
writer.write_encodable(&out).log().ok();
317+
writer.write_encodable(&out).log_ok();
318318
};
319319
self.db_exec_with_rows(&sql, &[], &mut output_fn);
320320
writer.write_encodable("").log()

native/src/core/package.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,11 @@ impl MagiskD {
465465
if let Ok(mut fd) = apk.open(O_RDONLY | O_CLOEXEC) {
466466
info.trusted_cert = read_certificate(&mut fd, MAGISK_VER_CODE);
467467
// Seek the fd back to start
468-
fd.seek(SeekFrom::Start(0)).log().ok();
468+
fd.seek(SeekFrom::Start(0)).log_ok();
469469
info.stub_apk_fd = Some(fd);
470470
}
471471

472-
apk.remove().log().ok();
472+
apk.remove().log_ok();
473473
}
474474

475475
pub fn get_manager_uid(&self, user: i32) -> i32 {

native/src/init/init.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl MagiskInit {
6666
let orig_init = FsPath::from(unsafe { Utf8CStr::from_ptr_unchecked(self.backup_init()) });
6767

6868
if orig_init.exists() {
69-
orig_init.rename_to(FsPath::from(cstr!("/init"))).log().ok();
69+
orig_init.rename_to(FsPath::from(cstr!("/init"))).log_ok();
7070
} else {
7171
// If the backup init is missing, this means that the boot ramdisk
7272
// was created from scratch, and the real init is in a separate CPIO,
@@ -151,7 +151,7 @@ pub unsafe extern "C" fn main(
151151
}
152152

153153
if getpid() == 1 {
154-
MagiskInit::new(argv).start().log().ok();
154+
MagiskInit::new(argv).start().log_ok();
155155
}
156156

157157
1

native/src/init/mount.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,20 @@ pub fn is_device_mounted(dev: u64, target: Pin<&mut CxxString>) -> bool {
7676
impl MagiskInit {
7777
pub(crate) fn prepare_data(&self) {
7878
debug!("Setup data tmp");
79-
fn inner() -> LoggedResult<()> {
80-
FsPath::from(cstr!("/data")).mkdir(0o755)?;
81-
unsafe {
82-
mount(
83-
raw_cstr!("magisk"),
84-
raw_cstr!("/data"),
85-
raw_cstr!("tmpfs"),
86-
0,
87-
raw_cstr!("mode=755").cast(),
88-
)
89-
}
90-
.as_os_err()?;
91-
92-
FsPath::from(cstr!("/init")).copy_to(FsPath::from(cstr!("/data/magiskinit")))?;
93-
FsPath::from(cstr!("/.backup")).copy_to(FsPath::from(cstr!("/data/.backup")))?;
94-
FsPath::from(cstr!("/overlay.d")).copy_to(FsPath::from(cstr!("/data/overlay.d")))?;
79+
FsPath::from(cstr!("/data")).mkdir(0o755).log_ok();
80+
unsafe {
81+
mount(
82+
raw_cstr!("magisk"),
83+
raw_cstr!("/data"),
84+
raw_cstr!("tmpfs"),
85+
0,
86+
raw_cstr!("mode=755").cast(),
87+
)
88+
}.as_os_err().log_ok();
9589

96-
Ok(())
97-
}
98-
inner().ok();
90+
FsPath::from(cstr!("/init")).copy_to(FsPath::from(cstr!("/data/magiskinit"))).log_ok();
91+
FsPath::from(cstr!("/.backup")).copy_to(FsPath::from(cstr!("/data/.backup"))).log_ok();
92+
FsPath::from(cstr!("/overlay.d")).copy_to(FsPath::from(cstr!("/data/overlay.d"))).log_ok();
9993
}
10094

10195
pub(crate) fn exec_init(&self) {

native/src/init/twostage.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ impl MagiskInit {
116116
debug!("Patch @ {:#010X} [{}] -> [{}]", off, from, to);
117117
}
118118
if let Ok(mut dest) = dest.create(O_CREAT | O_WRONLY, 0) {
119-
dest.write_all(map.as_ref()).log().ok();
119+
dest.write_all(map.as_ref()).log_ok();
120120
} else {
121121
error!("Failed to create {}", dest);
122122
}
123123
} else {
124124
error!("Failed to open {} for hexpatch", src);
125125
}
126-
clone_attr(src, dest).log().ok();
126+
clone_attr(src, dest).log_ok();
127127
unsafe {
128128
mount(dest.as_ptr(), src.as_ptr(), null(), MS_BIND, null())
129129
.as_os_err()

0 commit comments

Comments
 (0)