mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-29 22:14:27 +02:00
Address clippy warnings
This commit is contained in:
parent
82d1d19267
commit
a1b2830c06
@ -1031,8 +1031,9 @@ pub fn parse_mount_info(pid: &str) -> Vec<MountInfo> {
|
||||
res
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Default, Clone)]
|
||||
pub enum SharedFd {
|
||||
#[default]
|
||||
None,
|
||||
Shared(Arc<OwnedFd>),
|
||||
}
|
||||
@ -1058,9 +1059,3 @@ impl SharedFd {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SharedFd {
|
||||
fn default() -> Self {
|
||||
SharedFd::None
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ use crate::logging::{magisk_logging, start_log_daemon};
|
||||
use crate::package::ManagerInfo;
|
||||
use base::libc::{O_CLOEXEC, O_RDONLY};
|
||||
use base::{
|
||||
cstr, info, libc, open_fd, BufReadExt, DirEntry, Directory, FsPath, FsPathBuf, LoggedResult,
|
||||
ReadExt, Utf8CStr, Utf8CStrBufArr,
|
||||
cstr, info, libc, open_fd, BufReadExt, Directory, FsPath, FsPathBuf, LoggedResult, ReadExt,
|
||||
Utf8CStr, Utf8CStrBufArr,
|
||||
};
|
||||
use bit_set::BitSet;
|
||||
use bytemuck::bytes_of;
|
||||
@ -87,26 +87,27 @@ impl MagiskD {
|
||||
pub fn get_app_no_list(&self) -> BitSet {
|
||||
let mut list = BitSet::new();
|
||||
let _: LoggedResult<()> = try {
|
||||
let mut dir = Directory::open(self.app_data_dir())?;
|
||||
let mut app_data_dir = Directory::open(self.app_data_dir())?;
|
||||
// For each user
|
||||
loop {
|
||||
let entry: DirEntry;
|
||||
match dir.read()? {
|
||||
let entry = match app_data_dir.read()? {
|
||||
None => break,
|
||||
Some(e) => entry = e,
|
||||
}
|
||||
if let Ok(mut dir) = entry.open_as_dir() {
|
||||
// For each package
|
||||
loop {
|
||||
match dir.read()? {
|
||||
None => break,
|
||||
Some(e) => {
|
||||
let attr = e.get_attr()?;
|
||||
let app_id = to_app_id(attr.st.st_uid as i32);
|
||||
if app_id >= AID_APP_START && app_id <= AID_APP_END {
|
||||
let app_no = app_id - AID_APP_START;
|
||||
list.insert(app_no as usize);
|
||||
}
|
||||
Some(e) => e,
|
||||
};
|
||||
let mut user_dir = match entry.open_as_dir() {
|
||||
Err(_) => continue,
|
||||
Ok(dir) => dir,
|
||||
};
|
||||
// For each package
|
||||
loop {
|
||||
match user_dir.read()? {
|
||||
None => break,
|
||||
Some(e) => {
|
||||
let attr = e.get_attr()?;
|
||||
let app_id = to_app_id(attr.st.st_uid as i32);
|
||||
if (AID_APP_START..=AID_APP_END).contains(&app_id) {
|
||||
let app_no = app_id - AID_APP_START;
|
||||
list.insert(app_no as usize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -251,8 +251,10 @@ impl MagiskD {
|
||||
}
|
||||
|
||||
pub fn get_db_settings(&self) -> SqliteResult<DbSettings> {
|
||||
let mut cfg = DbSettings::default();
|
||||
cfg.zygisk = self.is_emulator;
|
||||
let mut cfg = DbSettings {
|
||||
zygisk: self.is_emulator,
|
||||
..Default::default()
|
||||
};
|
||||
self.db_exec_with_rows("SELECT * FROM settings", &[], &mut cfg)
|
||||
.sql_result()?;
|
||||
Ok(cfg)
|
||||
|
@ -143,13 +143,10 @@ static MAGISK_LOGD_FD: Mutex<SharedFd> = Mutex::new(SharedFd::new());
|
||||
fn with_logd_fd<F: FnOnce(&mut File) -> io::Result<()>>(f: F) {
|
||||
let fd = MAGISK_LOGD_FD.lock().unwrap().clone();
|
||||
// SAFETY: writing less than PIPE_BUF bytes is guaranteed to be atomic on Linux
|
||||
match unsafe { fd.as_file() } {
|
||||
None => return,
|
||||
Some(mut logd) => {
|
||||
if f(&mut logd).is_err() {
|
||||
// If any error occurs, shut down the logd pipe
|
||||
*MAGISK_LOGD_FD.lock().unwrap() = SharedFd::default();
|
||||
}
|
||||
if let Some(mut logd) = unsafe { fd.as_file() } {
|
||||
if f(&mut logd).is_err() {
|
||||
// If any error occurs, shut down the logd pipe
|
||||
*MAGISK_LOGD_FD.lock().unwrap() = SharedFd::default();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,20 +247,19 @@ impl ManagerInfo {
|
||||
.join(pkg)
|
||||
.join("dyn")
|
||||
.join("current.apk");
|
||||
let cert: Vec<u8>;
|
||||
let uid: i32;
|
||||
match apk.open(O_RDONLY | O_CLOEXEC) {
|
||||
let cert = match apk.open(O_RDONLY | O_CLOEXEC) {
|
||||
Ok(mut fd) => {
|
||||
uid = fd_get_attr(fd.as_raw_fd())
|
||||
.map(|attr| attr.st.st_uid as i32)
|
||||
.unwrap_or(-1);
|
||||
cert = read_certificate(&mut fd, MAGISK_VER_CODE)
|
||||
read_certificate(&mut fd, MAGISK_VER_CODE)
|
||||
}
|
||||
Err(_) => {
|
||||
warn!("pkg: no dyn APK, ignore");
|
||||
return Status::NotInstalled;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if cert.is_empty() || cert != self.trusted_cert {
|
||||
error!("pkg: dyn APK signature mismatch: {}", apk);
|
||||
@ -282,11 +281,10 @@ impl ManagerInfo {
|
||||
}
|
||||
let apk = FsPath::from(&arr);
|
||||
|
||||
let cert: Vec<u8>;
|
||||
match apk.open(O_RDONLY | O_CLOEXEC) {
|
||||
Ok(mut fd) => cert = read_certificate(&mut fd, -1),
|
||||
let cert = match apk.open(O_RDONLY | O_CLOEXEC) {
|
||||
Ok(mut fd) => read_certificate(&mut fd, -1),
|
||||
Err(_) => return Status::NotInstalled,
|
||||
}
|
||||
};
|
||||
|
||||
if cert.is_empty() || (pkg == self.repackaged_pkg && cert != self.repackaged_cert) {
|
||||
error!("pkg: repackaged APK signature invalid: {}", apk);
|
||||
@ -308,11 +306,10 @@ impl ManagerInfo {
|
||||
}
|
||||
let apk = FsPath::from(&arr);
|
||||
|
||||
let cert: Vec<u8>;
|
||||
match apk.open(O_RDONLY | O_CLOEXEC) {
|
||||
Ok(mut fd) => cert = read_certificate(&mut fd, MAGISK_VER_CODE),
|
||||
let cert = match apk.open(O_RDONLY | O_CLOEXEC) {
|
||||
Ok(mut fd) => read_certificate(&mut fd, MAGISK_VER_CODE),
|
||||
Err(_) => return Status::NotInstalled,
|
||||
}
|
||||
};
|
||||
|
||||
if cert.is_empty() || cert != self.trusted_cert {
|
||||
error!("pkg: APK signature mismatch: {}", apk);
|
||||
|
@ -76,7 +76,7 @@ impl MagiskD {
|
||||
|
||||
for uid in list.0 {
|
||||
let app_id = to_app_id(uid);
|
||||
if app_id >= AID_APP_START && app_id <= AID_APP_END {
|
||||
if (AID_APP_START..=AID_APP_END).contains(&app_id) {
|
||||
let app_no = app_id - AID_APP_START;
|
||||
if !app_list.contains(app_no as usize) {
|
||||
// The app_id is no longer installed
|
||||
|
Loading…
x
Reference in New Issue
Block a user