mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 16:07:39 +00:00
Remove unnecessary RefCell usage
This commit is contained in:
parent
a6e50d3648
commit
c81d7ff76c
@ -1,11 +1,10 @@
|
|||||||
use std::cell::RefCell;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::{Mutex, OnceLock};
|
use std::sync::{Mutex, OnceLock};
|
||||||
|
|
||||||
use crate::get_prop;
|
|
||||||
use base::{cstr, Directory, ResultExt, Utf8CStr, Utf8CStrBuf, Utf8CStrBufRef, WalkResult};
|
use base::{cstr, Directory, ResultExt, Utf8CStr, Utf8CStrBuf, Utf8CStrBufRef, WalkResult};
|
||||||
|
|
||||||
|
use crate::get_prop;
|
||||||
use crate::logging::{magisk_logging, zygisk_logging};
|
use crate::logging::{magisk_logging, zygisk_logging};
|
||||||
|
|
||||||
// Global magiskd singleton
|
// Global magiskd singleton
|
||||||
@ -13,7 +12,7 @@ pub static MAGISKD: OnceLock<MagiskD> = OnceLock::new();
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MagiskD {
|
pub struct MagiskD {
|
||||||
pub logd: Mutex<RefCell<Option<File>>>,
|
pub logd: Mutex<Option<File>>,
|
||||||
is_emulator: bool,
|
is_emulator: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,9 +151,8 @@ fn magisk_log_to_pipe(prio: i32, msg: &Utf8CStr) {
|
|||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
};
|
};
|
||||||
|
|
||||||
let logd_cell = magiskd.logd.lock().unwrap();
|
let mut guard = magiskd.logd.lock().unwrap();
|
||||||
let mut logd_ref = logd_cell.borrow_mut();
|
let logd = match guard.as_mut() {
|
||||||
let logd = match logd_ref.as_mut() {
|
|
||||||
None => return,
|
None => return,
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
};
|
};
|
||||||
@ -163,7 +162,7 @@ fn magisk_log_to_pipe(prio: i32, msg: &Utf8CStr) {
|
|||||||
// If any error occurs, shut down the logd pipe
|
// If any error occurs, shut down the logd pipe
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
print_log_error("magisk_log", e);
|
print_log_error("magisk_log", e);
|
||||||
*logd_ref = None;
|
*guard = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,31 +338,26 @@ impl MagiskD {
|
|||||||
libc::chown(path.as_ptr(), 0, 0);
|
libc::chown(path.as_ptr(), 0, 0);
|
||||||
let read = libc::open(path.as_ptr(), O_RDWR | O_CLOEXEC);
|
let read = libc::open(path.as_ptr(), O_RDWR | O_CLOEXEC);
|
||||||
let write = libc::open(path.as_ptr(), O_WRONLY | O_CLOEXEC);
|
let write = libc::open(path.as_ptr(), O_WRONLY | O_CLOEXEC);
|
||||||
let logd = self.logd.lock().unwrap();
|
*self.logd.lock().unwrap() = Some(File::from_raw_fd(write));
|
||||||
*logd.borrow_mut() = Some(File::from_raw_fd(write));
|
|
||||||
new_daemon_thread(logfile_writer, read as *mut c_void);
|
new_daemon_thread(logfile_writer, read as *mut c_void);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_log_pipe(&self) -> RawFd {
|
pub fn get_log_pipe(&self) -> RawFd {
|
||||||
let logd_cell = self.logd.lock().unwrap();
|
self.logd
|
||||||
let logd_ref = logd_cell.borrow();
|
.lock()
|
||||||
let logd = logd_ref.as_ref();
|
.unwrap()
|
||||||
match logd {
|
.as_ref()
|
||||||
None => -1,
|
.map_or(-1, |s| s.as_raw_fd())
|
||||||
Some(s) => s.as_raw_fd(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close_log_pipe(&self) {
|
pub fn close_log_pipe(&self) {
|
||||||
let guard = self.logd.lock().unwrap();
|
*self.logd.lock().unwrap() = None;
|
||||||
*guard.borrow_mut() = None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_logfile(&self) {
|
pub fn setup_logfile(&self) {
|
||||||
let logd_cell = self.logd.lock().unwrap();
|
let mut guard = self.logd.lock().unwrap();
|
||||||
let mut logd_ref = logd_cell.borrow_mut();
|
let logd = match guard.as_mut() {
|
||||||
let logd = match logd_ref.as_mut() {
|
|
||||||
None => return,
|
None => return,
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user