Address clippy warnings

This commit is contained in:
topjohnwu 2025-01-10 20:33:33 +08:00 committed by John Wu
parent 82d1d19267
commit a1b2830c06
6 changed files with 40 additions and 48 deletions

View File

@ -1031,8 +1031,9 @@ pub fn parse_mount_info(pid: &str) -> Vec<MountInfo> {
res res
} }
#[derive(Clone)] #[derive(Default, Clone)]
pub enum SharedFd { pub enum SharedFd {
#[default]
None, None,
Shared(Arc<OwnedFd>), Shared(Arc<OwnedFd>),
} }
@ -1058,9 +1059,3 @@ impl SharedFd {
} }
} }
} }
impl Default for SharedFd {
fn default() -> Self {
SharedFd::None
}
}

View File

@ -6,8 +6,8 @@ use crate::logging::{magisk_logging, start_log_daemon};
use crate::package::ManagerInfo; use crate::package::ManagerInfo;
use base::libc::{O_CLOEXEC, O_RDONLY}; use base::libc::{O_CLOEXEC, O_RDONLY};
use base::{ use base::{
cstr, info, libc, open_fd, BufReadExt, DirEntry, Directory, FsPath, FsPathBuf, LoggedResult, cstr, info, libc, open_fd, BufReadExt, Directory, FsPath, FsPathBuf, LoggedResult, ReadExt,
ReadExt, Utf8CStr, Utf8CStrBufArr, Utf8CStr, Utf8CStrBufArr,
}; };
use bit_set::BitSet; use bit_set::BitSet;
use bytemuck::bytes_of; use bytemuck::bytes_of;
@ -87,26 +87,27 @@ impl MagiskD {
pub fn get_app_no_list(&self) -> BitSet { pub fn get_app_no_list(&self) -> BitSet {
let mut list = BitSet::new(); let mut list = BitSet::new();
let _: LoggedResult<()> = try { 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 // For each user
loop { loop {
let entry: DirEntry; let entry = match app_data_dir.read()? {
match dir.read()? {
None => break, None => break,
Some(e) => entry = e, Some(e) => e,
} };
if let Ok(mut dir) = entry.open_as_dir() { let mut user_dir = match entry.open_as_dir() {
// For each package Err(_) => continue,
loop { Ok(dir) => dir,
match dir.read()? { };
None => break, // For each package
Some(e) => { loop {
let attr = e.get_attr()?; match user_dir.read()? {
let app_id = to_app_id(attr.st.st_uid as i32); None => break,
if app_id >= AID_APP_START && app_id <= AID_APP_END { Some(e) => {
let app_no = app_id - AID_APP_START; let attr = e.get_attr()?;
list.insert(app_no as usize); 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);
} }
} }
} }

View File

@ -251,8 +251,10 @@ impl MagiskD {
} }
pub fn get_db_settings(&self) -> SqliteResult<DbSettings> { pub fn get_db_settings(&self) -> SqliteResult<DbSettings> {
let mut cfg = DbSettings::default(); let mut cfg = DbSettings {
cfg.zygisk = self.is_emulator; zygisk: self.is_emulator,
..Default::default()
};
self.db_exec_with_rows("SELECT * FROM settings", &[], &mut cfg) self.db_exec_with_rows("SELECT * FROM settings", &[], &mut cfg)
.sql_result()?; .sql_result()?;
Ok(cfg) Ok(cfg)

View File

@ -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) { fn with_logd_fd<F: FnOnce(&mut File) -> io::Result<()>>(f: F) {
let fd = MAGISK_LOGD_FD.lock().unwrap().clone(); let fd = MAGISK_LOGD_FD.lock().unwrap().clone();
// SAFETY: writing less than PIPE_BUF bytes is guaranteed to be atomic on Linux // SAFETY: writing less than PIPE_BUF bytes is guaranteed to be atomic on Linux
match unsafe { fd.as_file() } { if let Some(mut logd) = unsafe { fd.as_file() } {
None => return, if f(&mut logd).is_err() {
Some(mut logd) => { // If any error occurs, shut down the logd pipe
if f(&mut logd).is_err() { *MAGISK_LOGD_FD.lock().unwrap() = SharedFd::default();
// If any error occurs, shut down the logd pipe
*MAGISK_LOGD_FD.lock().unwrap() = SharedFd::default();
}
} }
} }
} }

View File

@ -247,20 +247,19 @@ impl ManagerInfo {
.join(pkg) .join(pkg)
.join("dyn") .join("dyn")
.join("current.apk"); .join("current.apk");
let cert: Vec<u8>;
let uid: i32; let uid: i32;
match apk.open(O_RDONLY | O_CLOEXEC) { let cert = match apk.open(O_RDONLY | O_CLOEXEC) {
Ok(mut fd) => { Ok(mut fd) => {
uid = fd_get_attr(fd.as_raw_fd()) uid = fd_get_attr(fd.as_raw_fd())
.map(|attr| attr.st.st_uid as i32) .map(|attr| attr.st.st_uid as i32)
.unwrap_or(-1); .unwrap_or(-1);
cert = read_certificate(&mut fd, MAGISK_VER_CODE) read_certificate(&mut fd, MAGISK_VER_CODE)
} }
Err(_) => { Err(_) => {
warn!("pkg: no dyn APK, ignore"); warn!("pkg: no dyn APK, ignore");
return Status::NotInstalled; return Status::NotInstalled;
} }
} };
if cert.is_empty() || cert != self.trusted_cert { if cert.is_empty() || cert != self.trusted_cert {
error!("pkg: dyn APK signature mismatch: {}", apk); error!("pkg: dyn APK signature mismatch: {}", apk);
@ -282,11 +281,10 @@ impl ManagerInfo {
} }
let apk = FsPath::from(&arr); let apk = FsPath::from(&arr);
let cert: Vec<u8>; let cert = match apk.open(O_RDONLY | O_CLOEXEC) {
match apk.open(O_RDONLY | O_CLOEXEC) { Ok(mut fd) => read_certificate(&mut fd, -1),
Ok(mut fd) => cert = read_certificate(&mut fd, -1),
Err(_) => return Status::NotInstalled, Err(_) => return Status::NotInstalled,
} };
if cert.is_empty() || (pkg == self.repackaged_pkg && cert != self.repackaged_cert) { if cert.is_empty() || (pkg == self.repackaged_pkg && cert != self.repackaged_cert) {
error!("pkg: repackaged APK signature invalid: {}", apk); error!("pkg: repackaged APK signature invalid: {}", apk);
@ -308,11 +306,10 @@ impl ManagerInfo {
} }
let apk = FsPath::from(&arr); let apk = FsPath::from(&arr);
let cert: Vec<u8>; let cert = match apk.open(O_RDONLY | O_CLOEXEC) {
match apk.open(O_RDONLY | O_CLOEXEC) { Ok(mut fd) => read_certificate(&mut fd, MAGISK_VER_CODE),
Ok(mut fd) => cert = read_certificate(&mut fd, MAGISK_VER_CODE),
Err(_) => return Status::NotInstalled, Err(_) => return Status::NotInstalled,
} };
if cert.is_empty() || cert != self.trusted_cert { if cert.is_empty() || cert != self.trusted_cert {
error!("pkg: APK signature mismatch: {}", apk); error!("pkg: APK signature mismatch: {}", apk);

View File

@ -76,7 +76,7 @@ impl MagiskD {
for uid in list.0 { for uid in list.0 {
let app_id = to_app_id(uid); 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; let app_no = app_id - AID_APP_START;
if !app_list.contains(app_no as usize) { if !app_list.contains(app_no as usize) {
// The app_id is no longer installed // The app_id is no longer installed