Skip to content

Commit

Permalink
ksud: migrate to Rust 2024 edition (update headwaters)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann authored and 723593223 committed Mar 5, 2025
1 parent 381d024 commit 9be4fee
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion userspace/ksud/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ksud"
version = "0.1.0"
edition = "2021"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion userspace/ksud/src/apk_sign.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{ensure, Result};
use anyhow::{Result, ensure};
use std::io::{Read, Seek, SeekFrom};

pub fn get_apk_signature(apk: &str) -> Result<(u32, String)> {
Expand Down
6 changes: 3 additions & 3 deletions userspace/ksud/src/boot_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::path::PathBuf;
use std::process::Command;
use std::process::Stdio;

use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use anyhow::bail;
use anyhow::ensure;
use anyhow::Context;
use anyhow::Result;
use regex_lite::Regex;
use which::which;

Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn get_current_kmi() -> Result<String> {
}

fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result<String> {
use std::fs::{copy, File};
use std::fs::{File, copy};
use std::io::{BufReader, Read};
let kernel_path = workdir.join("kernel");
copy(kernel, &kernel_path).context("Failed to copy kernel")?;
Expand Down
2 changes: 1 addition & 1 deletion userspace/ksud/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{ensure, Context, Ok, Result};
use anyhow::{Context, Ok, Result, ensure};
use std::{
path::{Path, PathBuf},
process::Command,
Expand Down
2 changes: 1 addition & 1 deletion userspace/ksud/src/init_event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::defs::{KSU_MOUNT_SOURCE, NO_MOUNT_PATH, NO_TMPFS_PATH, TEMP_DIR};
use crate::module::{handle_updated_modules, prune_modules};
use crate::{assets, defs, ksucalls, restorecon, utils};
use anyhow::{Context, Result};
use anyhow::{Context, Result, bail};
use log::{info, warn};
use rustix::fs::{mount, MountFlags};
use std::path::Path;
Expand Down
4 changes: 2 additions & 2 deletions userspace/ksud/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
sepolicy,
};

use anyhow::{anyhow, bail, ensure, Context, Result};
use anyhow::{Context, Result, anyhow, bail, ensure};
use const_format::concatcp;
use is_executable::is_executable;
use java_properties::PropertiesIter;
Expand All @@ -16,7 +16,7 @@ use std::fs::{copy, rename};
use std::{
collections::HashMap,
env::var as env_var,
fs::{remove_dir_all, remove_file, set_permissions, File, Permissions},
fs::{File, Permissions, remove_dir_all, remove_file, set_permissions},
io::Cursor,
path::{Path, PathBuf},
process::Command,
Expand Down
2 changes: 1 addition & 1 deletion userspace/ksud/src/restorecon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::Path;
#[cfg(any(target_os = "linux", target_os = "android"))]
use anyhow::{Context, Ok};
#[cfg(any(target_os = "linux", target_os = "android"))]
use extattr::{lsetxattr, Flags as XattrFlags};
use extattr::{Flags as XattrFlags, lsetxattr};

pub const SYSTEM_CON: &str = "u:object_r:system_file:s0";
pub const ADB_CON: &str = "u:object_r:adb_data_file:s0";
Expand Down
6 changes: 3 additions & 3 deletions userspace/ksud/src/sepolicy.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use derive_new::new;
use nom::{
AsChar, IResult, Parser,
branch::alt,
bytes::complete::{tag, take_while, take_while1, take_while_m_n},
bytes::complete::{tag, take_while, take_while_m_n, take_while1},
character::complete::{space0, space1},
combinator::map,
AsChar, IResult, Parser,
};
use std::{ffi, path::Path, vec};

Expand Down
4 changes: 2 additions & 2 deletions userspace/ksud/src/su.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
#[cfg(any(target_os = "linux", target_os = "android"))]
use rustix::{
process::getuid,
thread::{set_thread_res_gid, set_thread_res_uid, Gid, Uid},
thread::{Gid, Uid, set_thread_res_gid, set_thread_res_uid},
};

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down Expand Up @@ -280,6 +280,6 @@ fn add_path_to_env(path: &str) -> Result<()> {
let new_path = PathBuf::from(path.trim_end_matches('/'));
paths.push(new_path);
let new_path_env = env::join_paths(paths)?;
env::set_var("PATH", new_path_env);
unsafe { env::set_var("PATH", new_path_env) };
Ok(())
}
10 changes: 5 additions & 5 deletions userspace/ksud/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, Context, Error, Ok, Result};
use anyhow::{Context, Error, Ok, Result, bail};
use std::{
fs::{create_dir_all, remove_file, write, File, OpenOptions},
fs::{File, OpenOptions, create_dir_all, remove_file, write},
io::{
ErrorKind::{AlreadyExists, NotFound},
Write,
Expand All @@ -11,7 +11,7 @@ use std::{

use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
#[allow(unused_imports)]
use std::fs::{set_permissions, Permissions};
use std::fs::{Permissions, set_permissions};
#[cfg(unix)]
use std::os::unix::prelude::PermissionsExt;

Expand All @@ -20,7 +20,7 @@ use std::path::PathBuf;
#[cfg(any(target_os = "linux", target_os = "android"))]
use rustix::{
process,
thread::{move_into_link_name_space, LinkNameSpaceType},
thread::{LinkNameSpaceType, move_into_link_name_space},
};

pub fn ensure_clean_dir(dir: impl AsRef<Path>) -> Result<()> {
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn get_zip_uncompressed_size(zip_path: &str) -> Result<u64> {
pub fn switch_mnt_ns(pid: i32) -> Result<()> {
use rustix::{
fd::AsFd,
fs::{open, Mode, OFlags},
fs::{Mode, OFlags, open},
};
let path = format!("/proc/{pid}/ns/mnt");
let fd = open(path, OFlags::RDONLY, Mode::from_raw_mode(0))?;
Expand Down

0 comments on commit 9be4fee

Please sign in to comment.