Skip to content

Commit

Permalink
Address clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Jan 10, 2025
1 parent 82d1d19 commit a1b2830
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 48 deletions.
9 changes: 2 additions & 7 deletions native/src/base/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>),
}
Expand All @@ -1058,9 +1059,3 @@ impl SharedFd {
}
}
}

impl Default for SharedFd {
fn default() -> Self {
SharedFd::None
}
}
39 changes: 20 additions & 19 deletions native/src/core/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions native/src/core/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions native/src/core/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
21 changes: 9 additions & 12 deletions native/src/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion native/src/core/su/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1b2830

Please sign in to comment.