2499 lines
98 KiB
Diff
2499 lines
98 KiB
Diff
|
|
From b1a45cacb15a1259a30452c4593c07a720534f0f Mon Sep 17 00:00:00 2001
|
||
|
|
From: liuxiaobo <liuxiaobo19@huawei.com>
|
||
|
|
Date: Thu, 27 Jun 2024 14:38:45 +0800
|
||
|
|
Subject: [PATCH] all: clean code
|
||
|
|
|
||
|
|
Signed-off-by: renoseven <dev@renoseven.net>
|
||
|
|
---
|
||
|
|
syscare-abi/build.rs | 33 ++++----
|
||
|
|
syscare-abi/src/patch_info.rs | 23 +++--
|
||
|
|
syscare-build/build.rs | 33 ++++----
|
||
|
|
syscare-build/src/build_root/mod.rs | 4 +-
|
||
|
|
syscare-build/src/build_root/package_root.rs | 4 +-
|
||
|
|
syscare-build/src/build_root/patch_root.rs | 4 +-
|
||
|
|
syscare-build/src/main.rs | 6 +-
|
||
|
|
syscare-build/src/package/build_root.rs | 4 +-
|
||
|
|
syscare-build/src/package/rpm/mod.rs | 7 +-
|
||
|
|
syscare-build/src/package/rpm/spec_builder.rs | 2 +-
|
||
|
|
syscare-build/src/package/rpm/spec_file.rs | 72 ++++++++--------
|
||
|
|
syscare-build/src/patch/metadata.rs | 4 +-
|
||
|
|
syscare-common/build.rs | 33 ++++----
|
||
|
|
syscare-common/src/ffi/os_str.rs | 11 +--
|
||
|
|
syscare-common/src/fs/flock.rs | 7 +-
|
||
|
|
syscare-common/src/fs/fs_impl.rs | 83 +++++++++----------
|
||
|
|
syscare-common/src/io/select.rs | 5 +-
|
||
|
|
syscare-common/src/os/cpu.rs | 4 +-
|
||
|
|
syscare-common/src/os/process.rs | 2 +-
|
||
|
|
syscare-common/src/os/user.rs | 67 ++++++++-------
|
||
|
|
syscare-common/src/os_str/iter.rs | 10 ++-
|
||
|
|
syscare-common/src/os_str/pattern.rs | 28 ++++---
|
||
|
|
syscare-common/src/os_str/utf8.rs | 2 +-
|
||
|
|
syscare-common/src/process/child.rs | 6 +-
|
||
|
|
syscare-common/src/process/stdio.rs | 2 +-
|
||
|
|
syscare/build.rs | 33 ++++----
|
||
|
|
syscare/src/executor/patch.rs | 4 +-
|
||
|
|
syscare/src/main.rs | 14 ++--
|
||
|
|
syscare/src/rpc/remote.rs | 19 ++---
|
||
|
|
syscared/build.rs | 33 ++++----
|
||
|
|
syscared/src/main.rs | 14 ++--
|
||
|
|
syscared/src/patch/driver/kpatch/sys.rs | 4 +-
|
||
|
|
syscared/src/patch/driver/mod.rs | 32 +++----
|
||
|
|
syscared/src/patch/driver/upatch/mod.rs | 4 +-
|
||
|
|
syscared/src/patch/manager.rs | 19 ++---
|
||
|
|
syscared/src/patch/monitor.rs | 6 +-
|
||
|
|
syscared/src/patch/resolver/kpatch.rs | 16 ++--
|
||
|
|
syscared/src/patch/resolver/mod.rs | 10 +--
|
||
|
|
syscared/src/patch/resolver/upatch.rs | 12 ++-
|
||
|
|
syscared/src/rpc/skeleton_impl/patch.rs | 14 ++--
|
||
|
|
upatch-build/build.rs | 33 ++++----
|
||
|
|
upatch-build/src/args.rs | 14 ++--
|
||
|
|
upatch-build/src/build_root.rs | 4 +-
|
||
|
|
upatch-build/src/compiler.rs | 29 ++++---
|
||
|
|
upatch-build/src/dwarf/mod.rs | 21 ++---
|
||
|
|
upatch-build/src/dwarf/relocate.rs | 14 ++--
|
||
|
|
upatch-build/src/elf/header.rs | 4 -
|
||
|
|
upatch-build/src/elf/read/elfs.rs | 10 +--
|
||
|
|
upatch-build/src/elf/read/section.rs | 19 ++---
|
||
|
|
upatch-build/src/elf/read/symbol.rs | 34 ++++----
|
||
|
|
upatch-build/src/elf/write/elfs.rs | 10 ++-
|
||
|
|
upatch-build/src/elf/write/symbol.rs | 40 ++++-----
|
||
|
|
upatch-build/src/file_relation.rs | 12 +--
|
||
|
|
upatch-build/src/main.rs | 16 ++--
|
||
|
|
upatch-build/src/pattern_path.rs | 26 +++---
|
||
|
|
upatch-build/src/resolve.rs | 79 +++++++++---------
|
||
|
|
upatch-build/src/rpc/remote.rs | 19 ++---
|
||
|
|
upatchd/build.rs | 33 ++++----
|
||
|
|
upatchd/src/helper/elf_resolver.rs | 4 +-
|
||
|
|
upatchd/src/helper/ioctl.rs | 1 +
|
||
|
|
upatchd/src/main.rs | 14 ++--
|
||
|
|
61 files changed, 560 insertions(+), 566 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/syscare-abi/build.rs b/syscare-abi/build.rs
|
||
|
|
index 8a86f63..ed83c43 100644
|
||
|
|
--- a/syscare-abi/build.rs
|
||
|
|
+++ b/syscare-abi/build.rs
|
||
|
|
@@ -12,26 +12,25 @@
|
||
|
|
* See the Mulan PSL v2 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
-use std::{env, process::Command};
|
||
|
|
+use std::{env, ffi::OsStr, os::unix::ffi::OsStrExt, process::Command};
|
||
|
|
|
||
|
|
fn rewrite_version() {
|
||
|
|
- const ENV_VERSION_NAME: &str = "BUILD_VERSION";
|
||
|
|
- const PKG_VERSION_NAME: &str = "CARGO_PKG_VERSION";
|
||
|
|
+ const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||
|
|
+ const ENV_VERSION: Option<&str> = option_env!("BUILD_VERSION");
|
||
|
|
|
||
|
|
- let version = env::var(ENV_VERSION_NAME).unwrap_or_else(|_| {
|
||
|
|
- let pkg_version = env::var(PKG_VERSION_NAME).expect("Failed to fetch package version");
|
||
|
|
- let git_output = Command::new("git")
|
||
|
|
- .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
- .output()
|
||
|
|
- .map(|output| String::from_utf8(output.stdout).expect("Failed to fetch git version"));
|
||
|
|
-
|
||
|
|
- match git_output {
|
||
|
|
- Ok(git_version) => format!("{}-g{}", pkg_version, git_version),
|
||
|
|
- Err(_) => pkg_version,
|
||
|
|
- }
|
||
|
|
- });
|
||
|
|
-
|
||
|
|
- println!("cargo:rustc-env={}={}", PKG_VERSION_NAME, version);
|
||
|
|
+ println!(
|
||
|
|
+ "cargo:rustc-env=CARGO_PKG_VERSION={}",
|
||
|
|
+ ENV_VERSION.map(String::from).unwrap_or_else(|| {
|
||
|
|
+ Command::new("git")
|
||
|
|
+ .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
+ .output()
|
||
|
|
+ .map(|output| {
|
||
|
|
+ let git_version = OsStr::from_bytes(&output.stdout).to_string_lossy();
|
||
|
|
+ format!("{}-g{}", PKG_VERSION, git_version)
|
||
|
|
+ })
|
||
|
|
+ .unwrap_or_else(|_| PKG_VERSION.to_string())
|
||
|
|
+ })
|
||
|
|
+ );
|
||
|
|
}
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
diff --git a/syscare-abi/src/patch_info.rs b/syscare-abi/src/patch_info.rs
|
||
|
|
index 08cc2c7..246f830 100644
|
||
|
|
--- a/syscare-abi/src/patch_info.rs
|
||
|
|
+++ b/syscare-abi/src/patch_info.rs
|
||
|
|
@@ -96,21 +96,18 @@ impl std::fmt::Display for PatchInfo {
|
||
|
|
writeln!(f, "patches:")?;
|
||
|
|
let last_idx = self.patches.len() - 1;
|
||
|
|
for (patch_idx, patch_file) in self.patches.iter().enumerate() {
|
||
|
|
- match patch_idx == last_idx {
|
||
|
|
- false => {
|
||
|
|
- if patch_idx >= LIST_DISPLAY_LIMIT {
|
||
|
|
- writeln!(f, "* ......")?;
|
||
|
|
- break;
|
||
|
|
- }
|
||
|
|
- writeln!(f, "* {}", patch_file.name.to_string_lossy())?
|
||
|
|
+ if patch_idx != last_idx {
|
||
|
|
+ if patch_idx >= LIST_DISPLAY_LIMIT {
|
||
|
|
+ writeln!(f, "* ......")?;
|
||
|
|
+ break;
|
||
|
|
}
|
||
|
|
- true => {
|
||
|
|
- if patch_idx >= LIST_DISPLAY_LIMIT {
|
||
|
|
- write!(f, "* ......")?;
|
||
|
|
- break;
|
||
|
|
- }
|
||
|
|
- write!(f, "* {}", patch_file.name.to_string_lossy())?
|
||
|
|
+ writeln!(f, "* {}", patch_file.name.to_string_lossy())?
|
||
|
|
+ } else {
|
||
|
|
+ if patch_idx >= LIST_DISPLAY_LIMIT {
|
||
|
|
+ write!(f, "* ......")?;
|
||
|
|
+ break;
|
||
|
|
}
|
||
|
|
+ write!(f, "* {}", patch_file.name.to_string_lossy())?
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
diff --git a/syscare-build/build.rs b/syscare-build/build.rs
|
||
|
|
index b3de093..1ca9609 100644
|
||
|
|
--- a/syscare-build/build.rs
|
||
|
|
+++ b/syscare-build/build.rs
|
||
|
|
@@ -12,26 +12,25 @@
|
||
|
|
* See the Mulan PSL v2 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
-use std::{env, process::Command};
|
||
|
|
+use std::{env, ffi::OsStr, os::unix::ffi::OsStrExt, process::Command};
|
||
|
|
|
||
|
|
fn rewrite_version() {
|
||
|
|
- const ENV_VERSION_NAME: &str = "BUILD_VERSION";
|
||
|
|
- const PKG_VERSION_NAME: &str = "CARGO_PKG_VERSION";
|
||
|
|
+ const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||
|
|
+ const ENV_VERSION: Option<&str> = option_env!("BUILD_VERSION");
|
||
|
|
|
||
|
|
- let version = env::var(ENV_VERSION_NAME).unwrap_or_else(|_| {
|
||
|
|
- let pkg_version = env::var(PKG_VERSION_NAME).expect("Failed to fetch package version");
|
||
|
|
- let git_output = Command::new("git")
|
||
|
|
- .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
- .output()
|
||
|
|
- .map(|output| String::from_utf8(output.stdout).expect("Failed to fetch git version"));
|
||
|
|
-
|
||
|
|
- match git_output {
|
||
|
|
- Ok(git_version) => format!("{}-g{}", pkg_version, git_version),
|
||
|
|
- Err(_) => pkg_version,
|
||
|
|
- }
|
||
|
|
- });
|
||
|
|
-
|
||
|
|
- println!("cargo:rustc-env={}={}", PKG_VERSION_NAME, version);
|
||
|
|
+ println!(
|
||
|
|
+ "cargo:rustc-env=CARGO_PKG_VERSION={}",
|
||
|
|
+ ENV_VERSION.map(String::from).unwrap_or_else(|| {
|
||
|
|
+ Command::new("git")
|
||
|
|
+ .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
+ .output()
|
||
|
|
+ .map(|output| {
|
||
|
|
+ let git_version = OsStr::from_bytes(&output.stdout).to_string_lossy();
|
||
|
|
+ format!("{}-g{}", PKG_VERSION, git_version)
|
||
|
|
+ })
|
||
|
|
+ .unwrap_or_else(|_| PKG_VERSION.to_string())
|
||
|
|
+ })
|
||
|
|
+ );
|
||
|
|
}
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
diff --git a/syscare-build/src/build_root/mod.rs b/syscare-build/src/build_root/mod.rs
|
||
|
|
index 6a12788..395fead 100644
|
||
|
|
--- a/syscare-build/src/build_root/mod.rs
|
||
|
|
+++ b/syscare-build/src/build_root/mod.rs
|
||
|
|
@@ -36,8 +36,8 @@ pub struct BuildRoot {
|
||
|
|
}
|
||
|
|
|
||
|
|
impl BuildRoot {
|
||
|
|
- pub fn new<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||
|
|
- let path = path.as_ref().to_path_buf();
|
||
|
|
+ pub fn new<P: AsRef<Path>>(directory: P) -> Result<Self> {
|
||
|
|
+ let path = directory.as_ref().to_path_buf();
|
||
|
|
let package = PackageRoot::new(path.join(PACKAGE_ROOT_NAME))?;
|
||
|
|
let patch = PatchRoot::new(path.join(PATCH_ROOT_NAME))?;
|
||
|
|
let log_file = path.join(BUILD_LOG_NAME);
|
||
|
|
diff --git a/syscare-build/src/build_root/package_root.rs b/syscare-build/src/build_root/package_root.rs
|
||
|
|
index 724a42b..75ff65d 100644
|
||
|
|
--- a/syscare-build/src/build_root/package_root.rs
|
||
|
|
+++ b/syscare-build/src/build_root/package_root.rs
|
||
|
|
@@ -32,8 +32,8 @@ pub struct PackageRoot {
|
||
|
|
}
|
||
|
|
|
||
|
|
impl PackageRoot {
|
||
|
|
- pub fn new<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||
|
|
- let path = path.as_ref().to_path_buf();
|
||
|
|
+ pub fn new<P: AsRef<Path>>(directory: P) -> Result<Self> {
|
||
|
|
+ let path = directory.as_ref().to_path_buf();
|
||
|
|
let source = path.join(SOURCE_DIR_NAME);
|
||
|
|
let debuginfo = path.join(DEBUGINFO_DIR_NAME);
|
||
|
|
let build_root = PackageBuildRoot::new(path.join(BUILD_ROOT_DIR_NAME))?;
|
||
|
|
diff --git a/syscare-build/src/build_root/patch_root.rs b/syscare-build/src/build_root/patch_root.rs
|
||
|
|
index af8ec6b..d493233 100644
|
||
|
|
--- a/syscare-build/src/build_root/patch_root.rs
|
||
|
|
+++ b/syscare-build/src/build_root/patch_root.rs
|
||
|
|
@@ -28,8 +28,8 @@ pub struct PatchRoot {
|
||
|
|
}
|
||
|
|
|
||
|
|
impl PatchRoot {
|
||
|
|
- pub fn new<P: AsRef<Path>>(base_dir: P) -> Result<Self> {
|
||
|
|
- let path = base_dir.as_ref().to_path_buf();
|
||
|
|
+ pub fn new<P: AsRef<Path>>(directory: P) -> Result<Self> {
|
||
|
|
+ let path = directory.as_ref().to_path_buf();
|
||
|
|
let build = path.join(BUILD_DIR_NAME);
|
||
|
|
let output = path.join(OUTPUT_DIR_NAME);
|
||
|
|
|
||
|
|
diff --git a/syscare-build/src/main.rs b/syscare-build/src/main.rs
|
||
|
|
index 1faa803..bfff3b4 100644
|
||
|
|
--- a/syscare-build/src/main.rs
|
||
|
|
+++ b/syscare-build/src/main.rs
|
||
|
|
@@ -217,10 +217,10 @@ impl SyscareBuild {
|
||
|
|
.find(|entry| entry.target_pkg.name == KERNEL_PKG_NAME);
|
||
|
|
|
||
|
|
match (pkg_entry, kernel_entry) {
|
||
|
|
- (Some(entry), Some(kernel_entry)) => Ok((
|
||
|
|
+ (Some(p_entry), Some(k_entry)) => Ok((
|
||
|
|
PatchType::KernelPatch,
|
||
|
|
- entry.clone(),
|
||
|
|
- Some(kernel_entry.clone()),
|
||
|
|
+ p_entry.clone(),
|
||
|
|
+ Some(k_entry.clone()),
|
||
|
|
)),
|
||
|
|
(None, Some(entry)) => Ok((PatchType::KernelPatch, entry.clone(), None)),
|
||
|
|
(Some(entry), None) => Ok((PatchType::UserPatch, entry.clone(), None)),
|
||
|
|
diff --git a/syscare-build/src/package/build_root.rs b/syscare-build/src/package/build_root.rs
|
||
|
|
index 6124156..d8ee182 100644
|
||
|
|
--- a/syscare-build/src/package/build_root.rs
|
||
|
|
+++ b/syscare-build/src/package/build_root.rs
|
||
|
|
@@ -36,8 +36,8 @@ pub struct PackageBuildRoot {
|
||
|
|
}
|
||
|
|
|
||
|
|
impl PackageBuildRoot {
|
||
|
|
- pub fn new<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||
|
|
- let path = path.as_ref().to_path_buf();
|
||
|
|
+ pub fn new<P: AsRef<Path>>(directory: P) -> Result<Self> {
|
||
|
|
+ let path = directory.as_ref().to_path_buf();
|
||
|
|
let build = path.join(BUILD_DIR_NAME);
|
||
|
|
let buildroot = path.join(BUILDROOT_DIR_NAME);
|
||
|
|
let rpms = path.join(RPMS_DIR_NAME);
|
||
|
|
diff --git a/syscare-build/src/package/rpm/mod.rs b/syscare-build/src/package/rpm/mod.rs
|
||
|
|
index 0e9f77c..4054f67 100644
|
||
|
|
--- a/syscare-build/src/package/rpm/mod.rs
|
||
|
|
+++ b/syscare-build/src/package/rpm/mod.rs
|
||
|
|
@@ -74,9 +74,10 @@ impl Package for RpmPackage {
|
||
|
|
}
|
||
|
|
|
||
|
|
let name = pkg_info[0].to_owned();
|
||
|
|
- let kind = match pkg_info[6] == SPEC_TAG_VALUE_NONE {
|
||
|
|
- true => PackageType::SourcePackage,
|
||
|
|
- false => PackageType::BinaryPackage,
|
||
|
|
+ let kind = if pkg_info[6] == SPEC_TAG_VALUE_NONE {
|
||
|
|
+ PackageType::SourcePackage
|
||
|
|
+ } else {
|
||
|
|
+ PackageType::BinaryPackage
|
||
|
|
};
|
||
|
|
let arch = pkg_info[1].to_owned();
|
||
|
|
let epoch = pkg_info[2].to_owned();
|
||
|
|
diff --git a/syscare-build/src/package/rpm/spec_builder.rs b/syscare-build/src/package/rpm/spec_builder.rs
|
||
|
|
index 5570c34..a24954f 100644
|
||
|
|
--- a/syscare-build/src/package/rpm/spec_builder.rs
|
||
|
|
+++ b/syscare-build/src/package/rpm/spec_builder.rs
|
||
|
|
@@ -113,7 +113,7 @@ impl RpmSpecBuilder {
|
||
|
|
patch_info.name
|
||
|
|
);
|
||
|
|
let pkg_version = format!("{}-{}", patch_info.version, patch_info.release);
|
||
|
|
- let pkg_root = Path::new(PKG_INSTALL_DIR).join(&patch_info.uuid.to_string());
|
||
|
|
+ let pkg_root = Path::new(PKG_INSTALL_DIR).join(patch_info.uuid.to_string());
|
||
|
|
|
||
|
|
let mut spec = RpmSpecFile::new(
|
||
|
|
pkg_name,
|
||
|
|
diff --git a/syscare-build/src/package/rpm/spec_file.rs b/syscare-build/src/package/rpm/spec_file.rs
|
||
|
|
index 17dcbe3..bd7b647 100644
|
||
|
|
--- a/syscare-build/src/package/rpm/spec_file.rs
|
||
|
|
+++ b/syscare-build/src/package/rpm/spec_file.rs
|
||
|
|
@@ -62,33 +62,33 @@ impl RpmSpecFile {
|
||
|
|
description: String,
|
||
|
|
) -> Self {
|
||
|
|
Self {
|
||
|
|
- defines: Default::default(),
|
||
|
|
+ defines: BTreeSet::default(),
|
||
|
|
name,
|
||
|
|
version,
|
||
|
|
release,
|
||
|
|
- group: Default::default(),
|
||
|
|
+ group: Option::default(),
|
||
|
|
license,
|
||
|
|
- url: Default::default(),
|
||
|
|
+ url: Option::default(),
|
||
|
|
summary,
|
||
|
|
- build_requires: Default::default(),
|
||
|
|
- requires: Default::default(),
|
||
|
|
- conflicts: Default::default(),
|
||
|
|
- suggests: Default::default(),
|
||
|
|
- recommends: Default::default(),
|
||
|
|
+ build_requires: HashSet::default(),
|
||
|
|
+ requires: HashSet::default(),
|
||
|
|
+ conflicts: HashSet::default(),
|
||
|
|
+ suggests: HashSet::default(),
|
||
|
|
+ recommends: HashSet::default(),
|
||
|
|
description,
|
||
|
|
prep: SPEC_SCRIPT_VALUE_NONE.to_string(),
|
||
|
|
build: SPEC_SCRIPT_VALUE_NONE.to_string(),
|
||
|
|
install: SPEC_SCRIPT_VALUE_NONE.to_string(),
|
||
|
|
- check: Default::default(),
|
||
|
|
- pre: Default::default(),
|
||
|
|
- post: Default::default(),
|
||
|
|
- preun: Default::default(),
|
||
|
|
- postun: Default::default(),
|
||
|
|
- defattr: Default::default(),
|
||
|
|
- files: Default::default(),
|
||
|
|
- source: Default::default(),
|
||
|
|
- patch: Default::default(),
|
||
|
|
- change_log: Default::default(),
|
||
|
|
+ check: Option::default(),
|
||
|
|
+ pre: Option::default(),
|
||
|
|
+ post: Option::default(),
|
||
|
|
+ preun: Option::default(),
|
||
|
|
+ postun: Option::default(),
|
||
|
|
+ defattr: Option::default(),
|
||
|
|
+ files: BTreeSet::default(),
|
||
|
|
+ source: BTreeSet::default(),
|
||
|
|
+ patch: BTreeSet::default(),
|
||
|
|
+ change_log: Option::default(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@@ -204,33 +204,33 @@ impl RpmSpecFile {
|
||
|
|
impl Default for RpmSpecFile {
|
||
|
|
fn default() -> Self {
|
||
|
|
Self {
|
||
|
|
- defines: Default::default(),
|
||
|
|
+ defines: BTreeSet::default(),
|
||
|
|
name: SPEC_TAG_VALUE_NONE.to_string(),
|
||
|
|
version: SPEC_TAG_VALUE_NONE.to_string(),
|
||
|
|
release: SPEC_TAG_VALUE_NONE.to_string(),
|
||
|
|
- group: Default::default(),
|
||
|
|
+ group: Option::default(),
|
||
|
|
license: SPEC_TAG_VALUE_NONE.to_string(),
|
||
|
|
- url: Default::default(),
|
||
|
|
+ url: Option::default(),
|
||
|
|
summary: SPEC_TAG_VALUE_NONE.to_string(),
|
||
|
|
- build_requires: Default::default(),
|
||
|
|
- requires: Default::default(),
|
||
|
|
- conflicts: Default::default(),
|
||
|
|
- suggests: Default::default(),
|
||
|
|
- recommends: Default::default(),
|
||
|
|
+ build_requires: HashSet::default(),
|
||
|
|
+ requires: HashSet::default(),
|
||
|
|
+ conflicts: HashSet::default(),
|
||
|
|
+ suggests: HashSet::default(),
|
||
|
|
+ recommends: HashSet::default(),
|
||
|
|
description: SPEC_TAG_VALUE_NONE.to_string(),
|
||
|
|
prep: SPEC_SCRIPT_VALUE_NONE.to_string(),
|
||
|
|
build: SPEC_SCRIPT_VALUE_NONE.to_string(),
|
||
|
|
install: SPEC_SCRIPT_VALUE_NONE.to_string(),
|
||
|
|
- check: Default::default(),
|
||
|
|
- pre: Default::default(),
|
||
|
|
- post: Default::default(),
|
||
|
|
- preun: Default::default(),
|
||
|
|
- postun: Default::default(),
|
||
|
|
- defattr: Default::default(),
|
||
|
|
- files: Default::default(),
|
||
|
|
- source: Default::default(),
|
||
|
|
- patch: Default::default(),
|
||
|
|
- change_log: Default::default(),
|
||
|
|
+ check: Option::default(),
|
||
|
|
+ pre: Option::default(),
|
||
|
|
+ post: Option::default(),
|
||
|
|
+ preun: Option::default(),
|
||
|
|
+ postun: Option::default(),
|
||
|
|
+ defattr: Option::default(),
|
||
|
|
+ files: BTreeSet::default(),
|
||
|
|
+ source: BTreeSet::default(),
|
||
|
|
+ patch: BTreeSet::default(),
|
||
|
|
+ change_log: Option::default(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
diff --git a/syscare-build/src/patch/metadata.rs b/syscare-build/src/patch/metadata.rs
|
||
|
|
index 918b487..0911693 100644
|
||
|
|
--- a/syscare-build/src/patch/metadata.rs
|
||
|
|
+++ b/syscare-build/src/patch/metadata.rs
|
||
|
|
@@ -35,8 +35,8 @@ pub struct PatchMetadata {
|
||
|
|
}
|
||
|
|
|
||
|
|
impl PatchMetadata {
|
||
|
|
- pub fn new<P: AsRef<Path>>(root_dir: P) -> Self {
|
||
|
|
- let root_dir = root_dir.as_ref().to_path_buf();
|
||
|
|
+ pub fn new<P: AsRef<Path>>(directory: P) -> Self {
|
||
|
|
+ let root_dir = directory.as_ref().to_path_buf();
|
||
|
|
let metadata_dir = root_dir.join(METADATA_DIR_NAME);
|
||
|
|
let package_path = root_dir.join(METADATA_PKG_NAME);
|
||
|
|
let metadata_path = metadata_dir.join(METADATA_FILE_NAME);
|
||
|
|
diff --git a/syscare-common/build.rs b/syscare-common/build.rs
|
||
|
|
index 1019998..ca9d78c 100644
|
||
|
|
--- a/syscare-common/build.rs
|
||
|
|
+++ b/syscare-common/build.rs
|
||
|
|
@@ -12,26 +12,25 @@
|
||
|
|
* See the Mulan PSL v2 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
-use std::{env, process::Command};
|
||
|
|
+use std::{env, ffi::OsStr, os::unix::ffi::OsStrExt, process::Command};
|
||
|
|
|
||
|
|
fn rewrite_version() {
|
||
|
|
- const ENV_VERSION_NAME: &str = "BUILD_VERSION";
|
||
|
|
- const PKG_VERSION_NAME: &str = "CARGO_PKG_VERSION";
|
||
|
|
+ const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||
|
|
+ const ENV_VERSION: Option<&str> = option_env!("BUILD_VERSION");
|
||
|
|
|
||
|
|
- let version = env::var(ENV_VERSION_NAME).unwrap_or_else(|_| {
|
||
|
|
- let pkg_version = env::var(PKG_VERSION_NAME).expect("Failed to fetch package version");
|
||
|
|
- let git_output = Command::new("git")
|
||
|
|
- .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
- .output()
|
||
|
|
- .map(|output| String::from_utf8(output.stdout).expect("Failed to fetch git version"));
|
||
|
|
-
|
||
|
|
- match git_output {
|
||
|
|
- Ok(git_version) => format!("{}-g{}", pkg_version, git_version),
|
||
|
|
- Err(_) => pkg_version,
|
||
|
|
- }
|
||
|
|
- });
|
||
|
|
-
|
||
|
|
- println!("cargo:rustc-env={}={}", PKG_VERSION_NAME, version);
|
||
|
|
+ println!(
|
||
|
|
+ "cargo:rustc-env=CARGO_PKG_VERSION={}",
|
||
|
|
+ ENV_VERSION.map(String::from).unwrap_or_else(|| {
|
||
|
|
+ Command::new("git")
|
||
|
|
+ .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
+ .output()
|
||
|
|
+ .map(|output| {
|
||
|
|
+ let git_version = OsStr::from_bytes(&output.stdout).to_string_lossy();
|
||
|
|
+ format!("{}-g{}", PKG_VERSION, git_version)
|
||
|
|
+ })
|
||
|
|
+ .unwrap_or_else(|_| PKG_VERSION.to_string())
|
||
|
|
+ })
|
||
|
|
+ );
|
||
|
|
}
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
diff --git a/syscare-common/src/ffi/os_str.rs b/syscare-common/src/ffi/os_str.rs
|
||
|
|
index 43a9adc..2db26c8 100644
|
||
|
|
--- a/syscare-common/src/ffi/os_str.rs
|
||
|
|
+++ b/syscare-common/src/ffi/os_str.rs
|
||
|
|
@@ -37,10 +37,7 @@ pub trait OsStrExt: AsRef<OsStr> {
|
||
|
|
|
||
|
|
let haystack = self.as_ref().as_bytes();
|
||
|
|
match haystack.get(index) {
|
||
|
|
- Some(&b) => {
|
||
|
|
- // This is bit magic equivalent to: b < 128 || b >= 192
|
||
|
|
- b as i8 >= -0x40
|
||
|
|
- }
|
||
|
|
+ Some(&b) => !(128..192).contains(&b),
|
||
|
|
None => index == haystack.len(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@@ -135,14 +132,12 @@ pub trait OsStrExt: AsRef<OsStr> {
|
||
|
|
}
|
||
|
|
|
||
|
|
fn split_whitespace(&self) -> Filter<Split<SplitFn>, FilterFn> {
|
||
|
|
- self.split(char::is_whitespace as SplitFn)
|
||
|
|
+ self.split(SplitFn::from(char::is_whitespace))
|
||
|
|
.filter(|s| !s.is_empty())
|
||
|
|
}
|
||
|
|
|
||
|
|
fn split_at(&self, mid: usize) -> (&OsStr, &OsStr) {
|
||
|
|
- if !self.is_char_boundary(mid) {
|
||
|
|
- panic!("Failed to slice osstring");
|
||
|
|
- }
|
||
|
|
+ debug_assert!(self.is_char_boundary(mid), "Split out of char boundary");
|
||
|
|
|
||
|
|
let (lhs, rhs) = self.as_ref().as_bytes().split_at(mid);
|
||
|
|
(OsStr::from_bytes(lhs), OsStr::from_bytes(rhs))
|
||
|
|
diff --git a/syscare-common/src/fs/flock.rs b/syscare-common/src/fs/flock.rs
|
||
|
|
index b5639a8..bfd39d7 100644
|
||
|
|
--- a/syscare-common/src/fs/flock.rs
|
||
|
|
+++ b/syscare-common/src/fs/flock.rs
|
||
|
|
@@ -57,9 +57,10 @@ impl FileLock {
|
||
|
|
impl FileLock {
|
||
|
|
pub fn new<P: AsRef<Path>>(path: P, kind: FileLockType) -> Result<Self> {
|
||
|
|
let file_path = path.as_ref();
|
||
|
|
- let inner = match file_path.exists() {
|
||
|
|
- true => File::open(file_path),
|
||
|
|
- false => File::create(file_path),
|
||
|
|
+ let inner = if file_path.exists() {
|
||
|
|
+ File::open(file_path)
|
||
|
|
+ } else {
|
||
|
|
+ File::create(file_path)
|
||
|
|
}
|
||
|
|
.with_context(|| format!("Failed to create flock on {}", file_path.display()))?;
|
||
|
|
|
||
|
|
diff --git a/syscare-common/src/fs/fs_impl.rs b/syscare-common/src/fs/fs_impl.rs
|
||
|
|
index af0f60c..e794c98 100644
|
||
|
|
--- a/syscare-common/src/fs/fs_impl.rs
|
||
|
|
+++ b/syscare-common/src/fs/fs_impl.rs
|
||
|
|
@@ -201,42 +201,50 @@ where
|
||
|
|
P: AsRef<Path>,
|
||
|
|
S: AsRef<OsStr>,
|
||
|
|
{
|
||
|
|
- let path = path.as_ref().to_cstring()?;
|
||
|
|
- let name = name.as_ref().to_cstring()?;
|
||
|
|
+ let file_path = path.as_ref().to_cstring()?;
|
||
|
|
+ let xattr_name = name.as_ref().to_cstring()?;
|
||
|
|
|
||
|
|
/*
|
||
|
|
* SAFETY:
|
||
|
|
* This libc function is marked 'unsafe' as unchecked buffer may cause overflow.
|
||
|
|
* In our implementation, the buffer is checked properly, so that would be safe.
|
||
|
|
*/
|
||
|
|
- let ret = unsafe { nix::libc::getxattr(path.as_ptr(), name.as_ptr(), null_mut(), 0) };
|
||
|
|
+ let mut ret =
|
||
|
|
+ unsafe { nix::libc::getxattr(file_path.as_ptr(), xattr_name.as_ptr(), null_mut(), 0) };
|
||
|
|
if ret == -1 {
|
||
|
|
return Err(std::io::Error::last_os_error()).rewrite_err(format!(
|
||
|
|
"Cannot get path {} xattr {}",
|
||
|
|
- path.to_string_lossy(),
|
||
|
|
- name.to_string_lossy()
|
||
|
|
+ file_path.to_string_lossy(),
|
||
|
|
+ xattr_name.to_string_lossy()
|
||
|
|
));
|
||
|
|
}
|
||
|
|
|
||
|
|
- let mut buf = vec![0; ret as usize];
|
||
|
|
- let value = buf.as_mut_ptr() as *mut c_void;
|
||
|
|
+ let mut buf = vec![0; ret.unsigned_abs()];
|
||
|
|
+ let value_ptr = buf.as_mut_ptr().cast::<c_void>();
|
||
|
|
|
||
|
|
/*
|
||
|
|
* SAFETY:
|
||
|
|
* This libc function is marked 'unsafe' as unchecked buffer may cause overflow.
|
||
|
|
* In our implementation, the buffer is checked properly, so that would be safe.
|
||
|
|
*/
|
||
|
|
- let ret = unsafe { nix::libc::getxattr(path.as_ptr(), name.as_ptr(), value, buf.len()) };
|
||
|
|
+ ret = unsafe {
|
||
|
|
+ nix::libc::getxattr(
|
||
|
|
+ file_path.as_ptr(),
|
||
|
|
+ xattr_name.as_ptr(),
|
||
|
|
+ value_ptr,
|
||
|
|
+ buf.len(),
|
||
|
|
+ )
|
||
|
|
+ };
|
||
|
|
if ret == -1 {
|
||
|
|
return Err(std::io::Error::last_os_error()).rewrite_err(format!(
|
||
|
|
"Cannot get path {} xattr {}",
|
||
|
|
- path.to_string_lossy(),
|
||
|
|
- name.to_string_lossy(),
|
||
|
|
+ file_path.to_string_lossy(),
|
||
|
|
+ xattr_name.to_string_lossy(),
|
||
|
|
));
|
||
|
|
}
|
||
|
|
|
||
|
|
- let value = CStr::from_bytes_with_nul(&buf[0..ret as usize])
|
||
|
|
- .expect("asdf")
|
||
|
|
+ let value = CStr::from_bytes_with_nul(&buf[0..ret.unsigned_abs()])
|
||
|
|
+ .unwrap_or_default()
|
||
|
|
.to_os_string();
|
||
|
|
|
||
|
|
Ok(value)
|
||
|
|
@@ -248,10 +256,10 @@ where
|
||
|
|
S: AsRef<OsStr>,
|
||
|
|
T: AsRef<OsStr>,
|
||
|
|
{
|
||
|
|
- let path = path.as_ref().to_cstring()?;
|
||
|
|
- let name = name.as_ref().to_cstring()?;
|
||
|
|
- let value = value.as_ref().to_cstring()?;
|
||
|
|
- let size = value.to_bytes_with_nul().len();
|
||
|
|
+ let file_path = path.as_ref().to_cstring()?;
|
||
|
|
+ let xattr_name = name.as_ref().to_cstring()?;
|
||
|
|
+ let xattr_value = value.as_ref().to_cstring()?;
|
||
|
|
+ let size = xattr_value.to_bytes_with_nul().len();
|
||
|
|
|
||
|
|
/*
|
||
|
|
* SAFETY:
|
||
|
|
@@ -260,9 +268,9 @@ where
|
||
|
|
*/
|
||
|
|
let ret = unsafe {
|
||
|
|
nix::libc::setxattr(
|
||
|
|
- path.as_ptr(),
|
||
|
|
- name.as_ptr(),
|
||
|
|
- value.as_ptr() as *const c_void,
|
||
|
|
+ file_path.as_ptr(),
|
||
|
|
+ xattr_name.as_ptr(),
|
||
|
|
+ xattr_value.as_ptr().cast::<c_void>(),
|
||
|
|
size,
|
||
|
|
0,
|
||
|
|
)
|
||
|
|
@@ -270,8 +278,8 @@ where
|
||
|
|
if ret == -1 {
|
||
|
|
return Err(std::io::Error::last_os_error()).rewrite_err(format!(
|
||
|
|
"Cannot set {} xattr {}",
|
||
|
|
- path.to_string_lossy(),
|
||
|
|
- name.to_string_lossy()
|
||
|
|
+ file_path.to_string_lossy(),
|
||
|
|
+ xattr_name.to_string_lossy()
|
||
|
|
));
|
||
|
|
}
|
||
|
|
|
||
|
|
@@ -425,13 +433,10 @@ where
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if let Some(file_name) = file_path.file_name() {
|
||
|
|
- match options.fuzz {
|
||
|
|
- false => {
|
||
|
|
- return file_name == name.as_ref();
|
||
|
|
- }
|
||
|
|
- true => {
|
||
|
|
- return file_name.contains(name.as_ref());
|
||
|
|
- }
|
||
|
|
+ if options.fuzz {
|
||
|
|
+ return file_name.contains(name.as_ref());
|
||
|
|
+ } else {
|
||
|
|
+ return file_name == name.as_ref();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
false
|
||
|
|
@@ -459,13 +464,10 @@ where
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if let Some(file_name) = file_path.file_name() {
|
||
|
|
- match options.fuzz {
|
||
|
|
- false => {
|
||
|
|
- return file_name == name.as_ref();
|
||
|
|
- }
|
||
|
|
- true => {
|
||
|
|
- return file_name.contains(name.as_ref());
|
||
|
|
- }
|
||
|
|
+ if options.fuzz {
|
||
|
|
+ return file_name.contains(name.as_ref());
|
||
|
|
+ } else {
|
||
|
|
+ return file_name == name.as_ref();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
false
|
||
|
|
@@ -526,13 +528,10 @@ where
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if let Some(file_name) = file_path.file_name() {
|
||
|
|
- match options.fuzz {
|
||
|
|
- false => {
|
||
|
|
- return file_name == name.as_ref();
|
||
|
|
- }
|
||
|
|
- true => {
|
||
|
|
- return file_name.contains(name.as_ref());
|
||
|
|
- }
|
||
|
|
+ if options.fuzz {
|
||
|
|
+ return file_name.contains(name.as_ref());
|
||
|
|
+ } else {
|
||
|
|
+ return file_name == name.as_ref();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
false
|
||
|
|
diff --git a/syscare-common/src/io/select.rs b/syscare-common/src/io/select.rs
|
||
|
|
index 59e28ac..5d9400f 100644
|
||
|
|
--- a/syscare-common/src/io/select.rs
|
||
|
|
+++ b/syscare-common/src/io/select.rs
|
||
|
|
@@ -32,7 +32,7 @@ impl Select {
|
||
|
|
Self::with_timeout(fds, None)
|
||
|
|
}
|
||
|
|
|
||
|
|
- pub fn with_timeout<I, F>(fds: I, timeout: Option<Duration>) -> Self
|
||
|
|
+ pub fn with_timeout<I, F>(fds: I, duration: Option<Duration>) -> Self
|
||
|
|
where
|
||
|
|
I: IntoIterator<Item = F>,
|
||
|
|
F: AsRawFd,
|
||
|
|
@@ -44,8 +44,7 @@ impl Select {
|
||
|
|
let readfds = FdSet::new();
|
||
|
|
let writefds = FdSet::new();
|
||
|
|
let errorfds = FdSet::new();
|
||
|
|
- let timeout = timeout
|
||
|
|
- .map(|timeout| TimeVal::new(timeout.as_secs() as i64, timeout.subsec_micros() as i64));
|
||
|
|
+ let timeout = duration.map(|t| TimeVal::new(t.as_secs() as i64, t.subsec_micros() as i64));
|
||
|
|
|
||
|
|
Self {
|
||
|
|
fd_set,
|
||
|
|
diff --git a/syscare-common/src/os/cpu.rs b/syscare-common/src/os/cpu.rs
|
||
|
|
index 62baa17..ead7eee 100644
|
||
|
|
--- a/syscare-common/src/os/cpu.rs
|
||
|
|
+++ b/syscare-common/src/os/cpu.rs
|
||
|
|
@@ -30,10 +30,10 @@ pub fn arch() -> &'static OsStr {
|
||
|
|
pub fn num() -> usize {
|
||
|
|
lazy_static! {
|
||
|
|
static ref CPU_NUM: usize = {
|
||
|
|
- let cpu_set = sched_getaffinity(getpid()).expect("Failed to get thread CPU affinity");
|
||
|
|
+ let cpu_set = sched_getaffinity(getpid()).unwrap_or_default();
|
||
|
|
let mut cpu_count = 0;
|
||
|
|
for i in 0..CpuSet::count() {
|
||
|
|
- if cpu_set.is_set(i).expect("Failed to check cpu set") {
|
||
|
|
+ if cpu_set.is_set(i).unwrap_or_default() {
|
||
|
|
cpu_count += 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
diff --git a/syscare-common/src/os/process.rs b/syscare-common/src/os/process.rs
|
||
|
|
index 2cf4ec9..d992372 100644
|
||
|
|
--- a/syscare-common/src/os/process.rs
|
||
|
|
+++ b/syscare-common/src/os/process.rs
|
||
|
|
@@ -30,7 +30,7 @@ pub fn id() -> i32 {
|
||
|
|
pub fn path() -> &'static Path {
|
||
|
|
lazy_static! {
|
||
|
|
static ref PROCESS_PATH: PathBuf =
|
||
|
|
- std::env::current_exe().expect("Read process path failed");
|
||
|
|
+ std::env::current_exe().unwrap_or_else(|_| PathBuf::from("/"));
|
||
|
|
}
|
||
|
|
PROCESS_PATH.as_path()
|
||
|
|
}
|
||
|
|
diff --git a/syscare-common/src/os/user.rs b/syscare-common/src/os/user.rs
|
||
|
|
index ebf2a14..db2e10e 100644
|
||
|
|
--- a/syscare-common/src/os/user.rs
|
||
|
|
+++ b/syscare-common/src/os/user.rs
|
||
|
|
@@ -12,71 +12,80 @@
|
||
|
|
* See the Mulan PSL v2 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
-use std::ffi::OsStr;
|
||
|
|
-use std::path::Path;
|
||
|
|
+use std::{
|
||
|
|
+ ffi::{CString, OsStr},
|
||
|
|
+ path::{Path, PathBuf},
|
||
|
|
+};
|
||
|
|
|
||
|
|
-use lazy_static::*;
|
||
|
|
-use nix::unistd::{getuid, User};
|
||
|
|
+use lazy_static::lazy_static;
|
||
|
|
+use nix::unistd::{getuid, Gid, Uid, User};
|
||
|
|
|
||
|
|
use crate::ffi::CStrExt;
|
||
|
|
|
||
|
|
-#[inline(always)]
|
||
|
|
fn info() -> &'static User {
|
||
|
|
lazy_static! {
|
||
|
|
- static ref USER: User = User::from_uid(getuid())
|
||
|
|
- .expect("Failed to read user info")
|
||
|
|
- .unwrap();
|
||
|
|
+ static ref USER_INFO: User = User::from_uid(getuid())
|
||
|
|
+ .unwrap_or_default()
|
||
|
|
+ .unwrap_or(User {
|
||
|
|
+ name: String::from("root"),
|
||
|
|
+ passwd: CString::default(),
|
||
|
|
+ uid: Uid::from_raw(0),
|
||
|
|
+ gid: Gid::from_raw(0),
|
||
|
|
+ gecos: CString::default(),
|
||
|
|
+ dir: PathBuf::from("/root"),
|
||
|
|
+ shell: PathBuf::from("/bin/sh"),
|
||
|
|
+ });
|
||
|
|
}
|
||
|
|
- &USER
|
||
|
|
+ &USER_INFO
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn name() -> &'static str {
|
||
|
|
- info().name.as_str()
|
||
|
|
+ self::info().name.as_str()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn passwd() -> &'static OsStr {
|
||
|
|
- info().passwd.as_os_str()
|
||
|
|
+ self::info().passwd.as_os_str()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn id() -> u32 {
|
||
|
|
- info().uid.as_raw()
|
||
|
|
+ self::info().uid.as_raw()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn gid() -> u32 {
|
||
|
|
- info().gid.as_raw()
|
||
|
|
+ self::info().gid.as_raw()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn gecos() -> &'static OsStr {
|
||
|
|
- info().gecos.as_os_str()
|
||
|
|
+ self::info().gecos.as_os_str()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn home() -> &'static Path {
|
||
|
|
- info().dir.as_path()
|
||
|
|
+ self::info().dir.as_path()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn shell() -> &'static Path {
|
||
|
|
- info().shell.as_path()
|
||
|
|
+ self::info().shell.as_path()
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn test() {
|
||
|
|
- println!("name: {}", name());
|
||
|
|
- assert!(!name().is_empty());
|
||
|
|
+ println!("name: {}", self::name());
|
||
|
|
+ assert!(!self::name().is_empty());
|
||
|
|
|
||
|
|
- println!("passwd: {}", passwd().to_string_lossy());
|
||
|
|
- assert!(!passwd().is_empty());
|
||
|
|
+ println!("passwd: {}", self::passwd().to_string_lossy());
|
||
|
|
+ assert!(!self::passwd().is_empty());
|
||
|
|
|
||
|
|
- println!("id: {}", id());
|
||
|
|
- assert!(id() > 0);
|
||
|
|
+ println!("id: {}", self::id());
|
||
|
|
+ assert!(id() < u32::MAX);
|
||
|
|
|
||
|
|
- println!("gid: {}", gid());
|
||
|
|
- assert!(gid() > 0);
|
||
|
|
+ println!("gid: {}", self::gid());
|
||
|
|
+ assert!(gid() < u32::MAX);
|
||
|
|
|
||
|
|
- println!("gecos: {}", gecos().to_string_lossy());
|
||
|
|
+ println!("gecos: {}", self::gecos().to_string_lossy());
|
||
|
|
|
||
|
|
- println!("home: {}", home().display());
|
||
|
|
- assert!(home().exists());
|
||
|
|
+ println!("home: {}", self::home().display());
|
||
|
|
+ assert!(self::home().exists());
|
||
|
|
|
||
|
|
- println!("shell: {}", shell().display());
|
||
|
|
- assert!(shell().exists());
|
||
|
|
+ println!("shell: {}", self::shell().display());
|
||
|
|
+ assert!(self::home().exists());
|
||
|
|
}
|
||
|
|
diff --git a/syscare-common/src/os_str/iter.rs b/syscare-common/src/os_str/iter.rs
|
||
|
|
index db48771..2fa5d3b 100644
|
||
|
|
--- a/syscare-common/src/os_str/iter.rs
|
||
|
|
+++ b/syscare-common/src/os_str/iter.rs
|
||
|
|
@@ -44,7 +44,7 @@ impl Iterator for CharIndices<'_> {
|
||
|
|
}
|
||
|
|
None => {
|
||
|
|
// Unable to parse utf-8 char, fallback to byte
|
||
|
|
- let result = (self.front_idx, char_bytes[0] as char);
|
||
|
|
+ let result = (self.front_idx, char::from(char_bytes[0]));
|
||
|
|
self.front_idx += 1;
|
||
|
|
|
||
|
|
Some(result)
|
||
|
|
@@ -68,7 +68,13 @@ impl DoubleEndedIterator for CharIndices<'_> {
|
||
|
|
None => {
|
||
|
|
// Unable to parse utf-8 char, fallback to byte
|
||
|
|
self.back_idx -= 1;
|
||
|
|
- Some((self.back_idx, *char_bytes.last().unwrap() as char))
|
||
|
|
+ Some((
|
||
|
|
+ self.back_idx,
|
||
|
|
+ char_bytes
|
||
|
|
+ .last()
|
||
|
|
+ .map(|b| char::from(*b))
|
||
|
|
+ .unwrap_or_default(),
|
||
|
|
+ ))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
diff --git a/syscare-common/src/os_str/pattern.rs b/syscare-common/src/os_str/pattern.rs
|
||
|
|
index 6e0c1f0..fe15c18 100644
|
||
|
|
--- a/syscare-common/src/os_str/pattern.rs
|
||
|
|
+++ b/syscare-common/src/os_str/pattern.rs
|
||
|
|
@@ -108,9 +108,10 @@ impl<'a> Searcher<'a> for CharLiteralSearcher<'a> {
|
||
|
|
match self.indices.next() {
|
||
|
|
Some((char_idx, c)) => {
|
||
|
|
let new_idx = char_idx + c.len_utf8();
|
||
|
|
- match self.literals.contains(&c) {
|
||
|
|
- true => SearchStep::Match(char_idx, new_idx),
|
||
|
|
- false => SearchStep::Reject(char_idx, new_idx),
|
||
|
|
+ if self.literals.contains(&c) {
|
||
|
|
+ SearchStep::Match(char_idx, new_idx)
|
||
|
|
+ } else {
|
||
|
|
+ SearchStep::Reject(char_idx, new_idx)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
None => SearchStep::Done,
|
||
|
|
@@ -123,9 +124,10 @@ impl<'a> ReverseSearcher<'a> for CharLiteralSearcher<'a> {
|
||
|
|
match self.indices.next_back() {
|
||
|
|
Some((char_idx, c)) => {
|
||
|
|
let new_idx = char_idx + c.len_utf8();
|
||
|
|
- match self.literals.contains(&c) {
|
||
|
|
- true => SearchStep::Match(char_idx, new_idx),
|
||
|
|
- false => SearchStep::Reject(char_idx, new_idx),
|
||
|
|
+ if self.literals.contains(&c) {
|
||
|
|
+ SearchStep::Match(char_idx, new_idx)
|
||
|
|
+ } else {
|
||
|
|
+ SearchStep::Reject(char_idx, new_idx)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
None => SearchStep::Done,
|
||
|
|
@@ -161,9 +163,10 @@ impl<'a, P: FnMut(char) -> bool> Searcher<'a> for CharPredicateSearcher<'a, P> {
|
||
|
|
match self.indices.next() {
|
||
|
|
Some((char_idx, c)) => {
|
||
|
|
let new_idx = char_idx + c.len_utf8();
|
||
|
|
- match (self.predicate)(c) {
|
||
|
|
- true => SearchStep::Match(char_idx, new_idx),
|
||
|
|
- false => SearchStep::Reject(char_idx, new_idx),
|
||
|
|
+ if (self.predicate)(c) {
|
||
|
|
+ SearchStep::Match(char_idx, new_idx)
|
||
|
|
+ } else {
|
||
|
|
+ SearchStep::Reject(char_idx, new_idx)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
None => SearchStep::Done,
|
||
|
|
@@ -176,9 +179,10 @@ impl<'a, P: FnMut(char) -> bool> ReverseSearcher<'a> for CharPredicateSearcher<'
|
||
|
|
match self.indices.next_back() {
|
||
|
|
Some((char_idx, c)) => {
|
||
|
|
let new_idx = char_idx + c.len_utf8();
|
||
|
|
- match (self.predicate)(c) {
|
||
|
|
- true => SearchStep::Match(char_idx, new_idx),
|
||
|
|
- false => SearchStep::Reject(char_idx, new_idx),
|
||
|
|
+ if (self.predicate)(c) {
|
||
|
|
+ SearchStep::Match(char_idx, new_idx)
|
||
|
|
+ } else {
|
||
|
|
+ SearchStep::Reject(char_idx, new_idx)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
None => SearchStep::Done,
|
||
|
|
diff --git a/syscare-common/src/os_str/utf8.rs b/syscare-common/src/os_str/utf8.rs
|
||
|
|
index 9a90bc0..8341df2 100644
|
||
|
|
--- a/syscare-common/src/os_str/utf8.rs
|
||
|
|
+++ b/syscare-common/src/os_str/utf8.rs
|
||
|
|
@@ -46,7 +46,7 @@ pub fn next_valid_char(bytes: &[u8]) -> Option<(usize, char)> {
|
||
|
|
}
|
||
|
|
|
||
|
|
let mut code = match char_width {
|
||
|
|
- 1 => return Some((1, first_byte as char)),
|
||
|
|
+ 1 => return Some((1, char::from(first_byte))),
|
||
|
|
2 => u32::from(first_byte & 0x1F) << 0x6,
|
||
|
|
3 => u32::from(first_byte & 0x0F) << 0xC,
|
||
|
|
4 => u32::from(first_byte & 0x07) << 0x12,
|
||
|
|
diff --git a/syscare-common/src/process/child.rs b/syscare-common/src/process/child.rs
|
||
|
|
index 4ce6664..0e8cf54 100644
|
||
|
|
--- a/syscare-common/src/process/child.rs
|
||
|
|
+++ b/syscare-common/src/process/child.rs
|
||
|
|
@@ -20,7 +20,7 @@ use std::{
|
||
|
|
thread::JoinHandle,
|
||
|
|
};
|
||
|
|
|
||
|
|
-use anyhow::{ensure, Context, Result};
|
||
|
|
+use anyhow::{anyhow, ensure, Context, Result};
|
||
|
|
use log::trace;
|
||
|
|
|
||
|
|
use super::{Stdio, StdioLevel};
|
||
|
|
@@ -81,7 +81,9 @@ impl Child {
|
||
|
|
pub fn wait_with_output(&mut self) -> Result<Output> {
|
||
|
|
let stdio_thread = self.capture_stdio()?;
|
||
|
|
let status = self.wait()?;
|
||
|
|
- let (stdout, stderr) = stdio_thread.join().expect("Failed to join stdio thread");
|
||
|
|
+ let (stdout, stderr) = stdio_thread
|
||
|
|
+ .join()
|
||
|
|
+ .map_err(|_| anyhow!("Failed to join stdio thread"))?;
|
||
|
|
|
||
|
|
Ok(Output {
|
||
|
|
status,
|
||
|
|
diff --git a/syscare-common/src/process/stdio.rs b/syscare-common/src/process/stdio.rs
|
||
|
|
index fca944f..450019a 100644
|
||
|
|
--- a/syscare-common/src/process/stdio.rs
|
||
|
|
+++ b/syscare-common/src/process/stdio.rs
|
||
|
|
@@ -90,7 +90,7 @@ impl Iterator for StdioReader {
|
||
|
|
match self.select.select().context("Failed to select stdio") {
|
||
|
|
Ok(result) => {
|
||
|
|
let stdio_map = &mut self.stdio_map;
|
||
|
|
- let outputs = result.into_iter().filter_map(|fd| match fd {
|
||
|
|
+ let outputs = result.into_iter().filter_map(|income| match income {
|
||
|
|
SelectResult::Readable(fd) => {
|
||
|
|
stdio_map.get_mut(&fd).and_then(|stdio| match stdio {
|
||
|
|
StdioLines::Stdout(lines) => {
|
||
|
|
diff --git a/syscare/build.rs b/syscare/build.rs
|
||
|
|
index 45eb14a..826ba22 100644
|
||
|
|
--- a/syscare/build.rs
|
||
|
|
+++ b/syscare/build.rs
|
||
|
|
@@ -12,26 +12,25 @@
|
||
|
|
* See the Mulan PSL v2 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
-use std::{env, process::Command};
|
||
|
|
+use std::{env, ffi::OsStr, os::unix::ffi::OsStrExt, process::Command};
|
||
|
|
|
||
|
|
fn rewrite_version() {
|
||
|
|
- const ENV_VERSION_NAME: &str = "BUILD_VERSION";
|
||
|
|
- const PKG_VERSION_NAME: &str = "CARGO_PKG_VERSION";
|
||
|
|
+ const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||
|
|
+ const ENV_VERSION: Option<&str> = option_env!("BUILD_VERSION");
|
||
|
|
|
||
|
|
- let version = env::var(ENV_VERSION_NAME).unwrap_or_else(|_| {
|
||
|
|
- let pkg_version = env::var(PKG_VERSION_NAME).expect("Failed to fetch package version");
|
||
|
|
- let git_output = Command::new("git")
|
||
|
|
- .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
- .output()
|
||
|
|
- .map(|output| String::from_utf8(output.stdout).expect("Failed to fetch git version"));
|
||
|
|
-
|
||
|
|
- match git_output {
|
||
|
|
- Ok(git_version) => format!("{}-g{}", pkg_version, git_version),
|
||
|
|
- Err(_) => pkg_version,
|
||
|
|
- }
|
||
|
|
- });
|
||
|
|
-
|
||
|
|
- println!("cargo:rustc-env={}={}", PKG_VERSION_NAME, version);
|
||
|
|
+ println!(
|
||
|
|
+ "cargo:rustc-env=CARGO_PKG_VERSION={}",
|
||
|
|
+ ENV_VERSION.map(String::from).unwrap_or_else(|| {
|
||
|
|
+ Command::new("git")
|
||
|
|
+ .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
+ .output()
|
||
|
|
+ .map(|output| {
|
||
|
|
+ let git_version = OsStr::from_bytes(&output.stdout).to_string_lossy();
|
||
|
|
+ format!("{}-g{}", PKG_VERSION, git_version)
|
||
|
|
+ })
|
||
|
|
+ .unwrap_or_else(|_| PKG_VERSION.to_string())
|
||
|
|
+ })
|
||
|
|
+ );
|
||
|
|
}
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
diff --git a/syscare/src/executor/patch.rs b/syscare/src/executor/patch.rs
|
||
|
|
index 1c4109b..98e719d 100644
|
||
|
|
--- a/syscare/src/executor/patch.rs
|
||
|
|
+++ b/syscare/src/executor/patch.rs
|
||
|
|
@@ -14,7 +14,7 @@
|
||
|
|
|
||
|
|
use std::{fmt::Write, path::PathBuf};
|
||
|
|
|
||
|
|
-use anyhow::{anyhow, Error, Result};
|
||
|
|
+use anyhow::{anyhow, Context, Error, Result};
|
||
|
|
use log::info;
|
||
|
|
|
||
|
|
use syscare_abi::{PackageInfo, PatchInfo, PatchListRecord, PatchStateRecord};
|
||
|
|
@@ -39,7 +39,7 @@ impl PatchCommandExecutor {
|
||
|
|
fn check_error(mut error_list: Vec<Error>) -> Result<()> {
|
||
|
|
match error_list.len() {
|
||
|
|
0 => Ok(()),
|
||
|
|
- 1 => Err(error_list.pop().unwrap()),
|
||
|
|
+ 1 => Err(error_list.pop().context("Invalid error")?),
|
||
|
|
_ => {
|
||
|
|
let mut err_msg = String::new();
|
||
|
|
for (idx, e) in error_list.into_iter().enumerate() {
|
||
|
|
diff --git a/syscare/src/main.rs b/syscare/src/main.rs
|
||
|
|
index dea5717..754307f 100644
|
||
|
|
--- a/syscare/src/main.rs
|
||
|
|
+++ b/syscare/src/main.rs
|
||
|
|
@@ -62,9 +62,10 @@ impl SyscareCLI {
|
||
|
|
let args = Arguments::new()?;
|
||
|
|
|
||
|
|
// Initialize logger
|
||
|
|
- let log_level_max = match args.verbose {
|
||
|
|
- false => LevelFilter::Info,
|
||
|
|
- true => LevelFilter::Trace,
|
||
|
|
+ let log_level_max = if args.verbose {
|
||
|
|
+ LevelFilter::Trace
|
||
|
|
+ } else {
|
||
|
|
+ LevelFilter::Info
|
||
|
|
};
|
||
|
|
let log_spec = LogSpecification::builder().default(log_level_max).build();
|
||
|
|
let logger = Logger::with(log_spec)
|
||
|
|
@@ -91,10 +92,9 @@ impl SyscareCLI {
|
||
|
|
|
||
|
|
debug!("Initializing command executors...");
|
||
|
|
let patch_lock_file = self.args.work_dir.join(PATCH_OP_LOCK_NAME);
|
||
|
|
- let executors = vec![
|
||
|
|
- Box::new(BuildCommandExecutor) as Box<dyn CommandExecutor>,
|
||
|
|
- Box::new(PatchCommandExecutor::new(patch_proxy, patch_lock_file))
|
||
|
|
- as Box<dyn CommandExecutor>,
|
||
|
|
+ let executors: Vec<Box<dyn CommandExecutor>> = vec![
|
||
|
|
+ Box::new(BuildCommandExecutor),
|
||
|
|
+ Box::new(PatchCommandExecutor::new(patch_proxy, patch_lock_file)),
|
||
|
|
];
|
||
|
|
|
||
|
|
let command = &self.args.command;
|
||
|
|
diff --git a/syscare/src/rpc/remote.rs b/syscare/src/rpc/remote.rs
|
||
|
|
index bd4c598..f2c9244 100644
|
||
|
|
--- a/syscare/src/rpc/remote.rs
|
||
|
|
+++ b/syscare/src/rpc/remote.rs
|
||
|
|
@@ -61,27 +61,22 @@ impl RpcRemote {
|
||
|
|
impl RpcRemote {
|
||
|
|
fn parse_error(&self, error: Error) -> anyhow::Error {
|
||
|
|
match error {
|
||
|
|
- Error::Transport(e) => {
|
||
|
|
+ Error::Transport(err) => {
|
||
|
|
anyhow!(
|
||
|
|
"Cannot connect to syscare daemon at unix://{}, {}",
|
||
|
|
self.socket.display(),
|
||
|
|
- e.source()
|
||
|
|
+ err.source()
|
||
|
|
.map(|e| e.to_string())
|
||
|
|
.unwrap_or_else(|| "Connection timeout".to_string())
|
||
|
|
)
|
||
|
|
}
|
||
|
|
- Error::Json(e) => {
|
||
|
|
- debug!("Json parse error: {:?}", e);
|
||
|
|
+ Error::Json(err) => {
|
||
|
|
+ debug!("Json parse error: {:?}", err);
|
||
|
|
anyhow!("Failed to parse response")
|
||
|
|
}
|
||
|
|
- Error::Rpc(ref e) => match e.message == "Method not found" {
|
||
|
|
- true => {
|
||
|
|
- anyhow!("Method is unimplemented")
|
||
|
|
- }
|
||
|
|
- false => {
|
||
|
|
- anyhow!("{}", e.message)
|
||
|
|
- }
|
||
|
|
- },
|
||
|
|
+ Error::Rpc(err) => {
|
||
|
|
+ anyhow!("{}", err.message)
|
||
|
|
+ }
|
||
|
|
_ => {
|
||
|
|
debug!("{:?}", error);
|
||
|
|
anyhow!("Response is invalid")
|
||
|
|
diff --git a/syscared/build.rs b/syscared/build.rs
|
||
|
|
index ea4bee7..3a07aa1 100644
|
||
|
|
--- a/syscared/build.rs
|
||
|
|
+++ b/syscared/build.rs
|
||
|
|
@@ -12,26 +12,25 @@
|
||
|
|
* See the Mulan PSL v2 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
-use std::{env, process::Command};
|
||
|
|
+use std::{env, ffi::OsStr, os::unix::ffi::OsStrExt, process::Command};
|
||
|
|
|
||
|
|
fn rewrite_version() {
|
||
|
|
- const ENV_VERSION_NAME: &str = "BUILD_VERSION";
|
||
|
|
- const PKG_VERSION_NAME: &str = "CARGO_PKG_VERSION";
|
||
|
|
+ const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||
|
|
+ const ENV_VERSION: Option<&str> = option_env!("BUILD_VERSION");
|
||
|
|
|
||
|
|
- let version = env::var(ENV_VERSION_NAME).unwrap_or_else(|_| {
|
||
|
|
- let pkg_version = env::var(PKG_VERSION_NAME).expect("Failed to fetch package version");
|
||
|
|
- let git_output = Command::new("git")
|
||
|
|
- .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
- .output()
|
||
|
|
- .map(|output| String::from_utf8(output.stdout).expect("Failed to fetch git version"));
|
||
|
|
-
|
||
|
|
- match git_output {
|
||
|
|
- Ok(git_version) => format!("{}-g{}", pkg_version, git_version),
|
||
|
|
- Err(_) => pkg_version,
|
||
|
|
- }
|
||
|
|
- });
|
||
|
|
-
|
||
|
|
- println!("cargo:rustc-env={}={}", PKG_VERSION_NAME, version);
|
||
|
|
+ println!(
|
||
|
|
+ "cargo:rustc-env=CARGO_PKG_VERSION={}",
|
||
|
|
+ ENV_VERSION.map(String::from).unwrap_or_else(|| {
|
||
|
|
+ Command::new("git")
|
||
|
|
+ .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
+ .output()
|
||
|
|
+ .map(|output| {
|
||
|
|
+ let git_version = OsStr::from_bytes(&output.stdout).to_string_lossy();
|
||
|
|
+ format!("{}-g{}", PKG_VERSION, git_version)
|
||
|
|
+ })
|
||
|
|
+ .unwrap_or_else(|_| PKG_VERSION.to_string())
|
||
|
|
+ })
|
||
|
|
+ );
|
||
|
|
}
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
diff --git a/syscared/src/main.rs b/syscared/src/main.rs
|
||
|
|
index f13a9f8..42e9564 100644
|
||
|
|
--- a/syscared/src/main.rs
|
||
|
|
+++ b/syscared/src/main.rs
|
||
|
|
@@ -129,9 +129,10 @@ impl Daemon {
|
||
|
|
|
||
|
|
// Initialize logger
|
||
|
|
let max_level = args.log_level;
|
||
|
|
- let stdout_level = match args.daemon {
|
||
|
|
- true => LevelFilter::Off,
|
||
|
|
- false => max_level,
|
||
|
|
+ let stdout_level = if args.daemon {
|
||
|
|
+ LevelFilter::Off
|
||
|
|
+ } else {
|
||
|
|
+ max_level
|
||
|
|
};
|
||
|
|
let log_spec = LogSpecification::builder().default(max_level).build();
|
||
|
|
let file_spec = FileSpec::default()
|
||
|
|
@@ -210,9 +211,10 @@ impl Daemon {
|
||
|
|
|
||
|
|
fs::set_permissions(
|
||
|
|
&socket_file,
|
||
|
|
- match socket_owner.as_raw() == socket_group.as_raw() {
|
||
|
|
- true => Permissions::from_mode(SOCKET_FILE_PERM_STRICT),
|
||
|
|
- false => Permissions::from_mode(SOCKET_FILE_PERM),
|
||
|
|
+ if socket_owner.as_raw() == socket_group.as_raw() {
|
||
|
|
+ Permissions::from_mode(SOCKET_FILE_PERM_STRICT)
|
||
|
|
+ } else {
|
||
|
|
+ Permissions::from_mode(SOCKET_FILE_PERM)
|
||
|
|
},
|
||
|
|
)?;
|
||
|
|
|
||
|
|
diff --git a/syscared/src/patch/driver/kpatch/sys.rs b/syscared/src/patch/driver/kpatch/sys.rs
|
||
|
|
index ea6b68f..22efa93 100644
|
||
|
|
--- a/syscared/src/patch/driver/kpatch/sys.rs
|
||
|
|
+++ b/syscared/src/patch/driver/kpatch/sys.rs
|
||
|
|
@@ -92,7 +92,7 @@ pub fn apply_patch(patch: &KernelPatch) -> Result<()> {
|
||
|
|
CString::new("")?.as_c_str(),
|
||
|
|
kmod::ModuleInitFlags::MODULE_INIT_IGNORE_VERMAGIC,
|
||
|
|
)
|
||
|
|
- .map_err(|e| anyhow!("Kpatch: {}", std::io::Error::from_raw_os_error(e as i32)))
|
||
|
|
+ .map_err(|e| anyhow!("Kpatch: {}", std::io::Error::from(e)))
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn remove_patch(patch: &KernelPatch) -> Result<()> {
|
||
|
|
@@ -105,7 +105,7 @@ pub fn remove_patch(patch: &KernelPatch) -> Result<()> {
|
||
|
|
patch.module_name.to_cstring()?.as_c_str(),
|
||
|
|
kmod::DeleteModuleFlags::O_NONBLOCK,
|
||
|
|
)
|
||
|
|
- .map_err(|e| anyhow!("Kpatch: {}", std::io::Error::from_raw_os_error(e as i32)))
|
||
|
|
+ .map_err(|e| anyhow!("Kpatch: {}", std::io::Error::from(e)))
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn active_patch(patch: &KernelPatch) -> Result<()> {
|
||
|
|
diff --git a/syscared/src/patch/driver/mod.rs b/syscared/src/patch/driver/mod.rs
|
||
|
|
index d64c2d4..7a57579 100644
|
||
|
|
--- a/syscared/src/patch/driver/mod.rs
|
||
|
|
+++ b/syscared/src/patch/driver/mod.rs
|
||
|
|
@@ -39,15 +39,15 @@ pub struct PatchDriver {
|
||
|
|
impl PatchDriver {
|
||
|
|
fn check_conflict_functions(&self, patch: &Patch) -> Result<()> {
|
||
|
|
match patch {
|
||
|
|
- Patch::KernelPatch(patch) => self.kpatch.check_conflict_functions(patch),
|
||
|
|
- Patch::UserPatch(patch) => self.upatch.check_conflict_functions(patch),
|
||
|
|
+ Patch::KernelPatch(kpatch) => self.kpatch.check_conflict_functions(kpatch),
|
||
|
|
+ Patch::UserPatch(upatch) => self.upatch.check_conflict_functions(upatch),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
fn check_override_functions(&self, patch: &Patch) -> Result<()> {
|
||
|
|
match patch {
|
||
|
|
- Patch::KernelPatch(patch) => self.kpatch.check_override_functions(patch),
|
||
|
|
- Patch::UserPatch(patch) => self.upatch.check_override_functions(patch),
|
||
|
|
+ Patch::KernelPatch(kpatch) => self.kpatch.check_override_functions(kpatch),
|
||
|
|
+ Patch::UserPatch(upatch) => self.upatch.check_override_functions(upatch),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@@ -71,8 +71,8 @@ impl PatchDriver {
|
||
|
|
/// Fetch and return the patch status.
|
||
|
|
pub fn patch_status(&self, patch: &Patch) -> Result<PatchStatus> {
|
||
|
|
match patch {
|
||
|
|
- Patch::KernelPatch(patch) => self.kpatch.status(patch),
|
||
|
|
- Patch::UserPatch(patch) => self.upatch.status(patch),
|
||
|
|
+ Patch::KernelPatch(kpatch) => self.kpatch.status(kpatch),
|
||
|
|
+ Patch::UserPatch(upatch) => self.upatch.status(upatch),
|
||
|
|
}
|
||
|
|
.with_context(|| format!("Failed to get patch '{}' status", patch))
|
||
|
|
}
|
||
|
|
@@ -84,8 +84,8 @@ impl PatchDriver {
|
||
|
|
return Ok(());
|
||
|
|
}
|
||
|
|
match patch {
|
||
|
|
- Patch::KernelPatch(patch) => self.kpatch.check(patch),
|
||
|
|
- Patch::UserPatch(patch) => self.upatch.check(patch),
|
||
|
|
+ Patch::KernelPatch(kpatch) => self.kpatch.check(kpatch),
|
||
|
|
+ Patch::UserPatch(upatch) => self.upatch.check(upatch),
|
||
|
|
}
|
||
|
|
.with_context(|| format!("Patch '{}' is not patchable", patch))
|
||
|
|
}
|
||
|
|
@@ -104,8 +104,8 @@ impl PatchDriver {
|
||
|
|
/// After this action, the patch status would be changed to 'DEACTIVED'.
|
||
|
|
pub fn apply_patch(&mut self, patch: &Patch) -> Result<()> {
|
||
|
|
match patch {
|
||
|
|
- Patch::KernelPatch(patch) => self.kpatch.apply(patch),
|
||
|
|
- Patch::UserPatch(patch) => self.upatch.apply(patch),
|
||
|
|
+ Patch::KernelPatch(kpatch) => self.kpatch.apply(kpatch),
|
||
|
|
+ Patch::UserPatch(upatch) => self.upatch.apply(upatch),
|
||
|
|
}
|
||
|
|
.with_context(|| format!("Failed to apply patch '{}'", patch))
|
||
|
|
}
|
||
|
|
@@ -114,8 +114,8 @@ impl PatchDriver {
|
||
|
|
/// After this action, the patch status would be changed to 'NOT-APPLIED'.
|
||
|
|
pub fn remove_patch(&mut self, patch: &Patch) -> Result<()> {
|
||
|
|
match patch {
|
||
|
|
- Patch::KernelPatch(patch) => self.kpatch.remove(patch),
|
||
|
|
- Patch::UserPatch(patch) => self.upatch.remove(patch),
|
||
|
|
+ Patch::KernelPatch(kpatch) => self.kpatch.remove(kpatch),
|
||
|
|
+ Patch::UserPatch(upatch) => self.upatch.remove(upatch),
|
||
|
|
}
|
||
|
|
.with_context(|| format!("Failed to remove patch '{}'", patch))
|
||
|
|
}
|
||
|
|
@@ -127,8 +127,8 @@ impl PatchDriver {
|
||
|
|
self.check_conflict_functions(patch)?;
|
||
|
|
}
|
||
|
|
match patch {
|
||
|
|
- Patch::KernelPatch(patch) => self.kpatch.active(patch),
|
||
|
|
- Patch::UserPatch(patch) => self.upatch.active(patch),
|
||
|
|
+ Patch::KernelPatch(kpatch) => self.kpatch.active(kpatch),
|
||
|
|
+ Patch::UserPatch(upatch) => self.upatch.active(upatch),
|
||
|
|
}
|
||
|
|
.with_context(|| format!("Failed to active patch '{}'", patch))
|
||
|
|
}
|
||
|
|
@@ -140,8 +140,8 @@ impl PatchDriver {
|
||
|
|
self.check_override_functions(patch)?;
|
||
|
|
}
|
||
|
|
match patch {
|
||
|
|
- Patch::KernelPatch(patch) => self.kpatch.deactive(patch),
|
||
|
|
- Patch::UserPatch(patch) => self.upatch.deactive(patch),
|
||
|
|
+ Patch::KernelPatch(kpatch) => self.kpatch.deactive(kpatch),
|
||
|
|
+ Patch::UserPatch(upatch) => self.upatch.deactive(upatch),
|
||
|
|
}
|
||
|
|
.with_context(|| format!("Failed to deactive patch '{}'", patch))
|
||
|
|
}
|
||
|
|
diff --git a/syscared/src/patch/driver/upatch/mod.rs b/syscared/src/patch/driver/upatch/mod.rs
|
||
|
|
index 66eecf5..73ef94e 100644
|
||
|
|
--- a/syscared/src/patch/driver/upatch/mod.rs
|
||
|
|
+++ b/syscared/src/patch/driver/upatch/mod.rs
|
||
|
|
@@ -227,8 +227,8 @@ impl UserPatchDriver {
|
||
|
|
Err(_) => return,
|
||
|
|
};
|
||
|
|
|
||
|
|
- let mut target_map = target_map.write();
|
||
|
|
- let patch_target = match target_map.get_mut(target_elf) {
|
||
|
|
+ let mut patch_target_map = target_map.write();
|
||
|
|
+ let patch_target = match patch_target_map.get_mut(target_elf) {
|
||
|
|
Some(target) => target,
|
||
|
|
None => return,
|
||
|
|
};
|
||
|
|
diff --git a/syscared/src/patch/manager.rs b/syscared/src/patch/manager.rs
|
||
|
|
index f633567..d156e4a 100644
|
||
|
|
--- a/syscared/src/patch/manager.rs
|
||
|
|
+++ b/syscared/src/patch/manager.rs
|
||
|
|
@@ -246,12 +246,11 @@ impl PatchManager {
|
||
|
|
|
||
|
|
debug!("Reading patch status...");
|
||
|
|
let status_file = &self.patch_status_file;
|
||
|
|
- let status_map: HashMap<Uuid, PatchStatus> = match status_file.exists() {
|
||
|
|
- true => serde::deserialize(status_file).context("Failed to read patch status")?,
|
||
|
|
- false => {
|
||
|
|
- warn!("Cannot find patch status file");
|
||
|
|
- return Ok(());
|
||
|
|
- }
|
||
|
|
+ let status_map: HashMap<Uuid, PatchStatus> = if status_file.exists() {
|
||
|
|
+ serde::deserialize(status_file).context("Failed to read patch status")?
|
||
|
|
+ } else {
|
||
|
|
+ warn!("Cannot find patch status file");
|
||
|
|
+ return Ok(());
|
||
|
|
};
|
||
|
|
|
||
|
|
/*
|
||
|
|
@@ -301,7 +300,7 @@ impl PatchManager {
|
||
|
|
pub fn rescan_patches(&mut self) -> Result<()> {
|
||
|
|
self.patch_map = Self::scan_patches(&self.patch_install_dir)?;
|
||
|
|
|
||
|
|
- let status_keys = self.status_map.keys().cloned().collect::<Vec<_>>();
|
||
|
|
+ let status_keys = self.status_map.keys().copied().collect::<Vec<_>>();
|
||
|
|
for patch_uuid in status_keys {
|
||
|
|
if !self.patch_map.contains_key(&patch_uuid) {
|
||
|
|
trace!("Patch '{}' was removed, remove its status", patch_uuid);
|
||
|
|
@@ -362,9 +361,9 @@ impl PatchManager {
|
||
|
|
let mut patch_map = IndexMap::new();
|
||
|
|
|
||
|
|
info!("Scanning patches from {}...", directory.as_ref().display());
|
||
|
|
- for patch_root in fs::list_dirs(directory, TRAVERSE_OPTION)? {
|
||
|
|
- let resolve_result = PatchResolver::resolve_patch(&patch_root)
|
||
|
|
- .with_context(|| format!("Failed to resolve patch from {}", patch_root.display()));
|
||
|
|
+ for patch_dir in fs::list_dirs(directory, TRAVERSE_OPTION)? {
|
||
|
|
+ let resolve_result = PatchResolver::resolve_patch(&patch_dir)
|
||
|
|
+ .with_context(|| format!("Failed to resolve patch from {}", patch_dir.display()));
|
||
|
|
match resolve_result {
|
||
|
|
Ok(patches) => {
|
||
|
|
for patch in patches {
|
||
|
|
diff --git a/syscared/src/patch/monitor.rs b/syscared/src/patch/monitor.rs
|
||
|
|
index 1798781..c793600 100644
|
||
|
|
--- a/syscared/src/patch/monitor.rs
|
||
|
|
+++ b/syscared/src/patch/monitor.rs
|
||
|
|
@@ -44,13 +44,13 @@ impl PatchMonitor {
|
||
|
|
patch_root: P,
|
||
|
|
patch_manager: Arc<RwLock<PatchManager>>,
|
||
|
|
) -> Result<Self> {
|
||
|
|
- let patch_root = patch_root.as_ref().join(PATCH_INSTALL_DIR);
|
||
|
|
+ let patch_install_dir = patch_root.as_ref().join(PATCH_INSTALL_DIR);
|
||
|
|
|
||
|
|
let inotify = Arc::new(Mutex::new(Some({
|
||
|
|
let mut inotify = Inotify::init().context("Failed to initialize inotify")?;
|
||
|
|
inotify
|
||
|
|
.add_watch(
|
||
|
|
- &patch_root,
|
||
|
|
+ &patch_install_dir,
|
||
|
|
WatchMask::CREATE | WatchMask::DELETE | WatchMask::ONLYDIR,
|
||
|
|
)
|
||
|
|
.context("Failed to monitor patch directory")?;
|
||
|
|
@@ -59,7 +59,7 @@ impl PatchMonitor {
|
||
|
|
})));
|
||
|
|
|
||
|
|
let monitor_thread = MonitorThread {
|
||
|
|
- patch_root,
|
||
|
|
+ patch_root: patch_install_dir,
|
||
|
|
inotify: inotify.clone(),
|
||
|
|
patch_manager,
|
||
|
|
}
|
||
|
|
diff --git a/syscared/src/patch/resolver/kpatch.rs b/syscared/src/patch/resolver/kpatch.rs
|
||
|
|
index 524482e..7946c42 100644
|
||
|
|
--- a/syscared/src/patch/resolver/kpatch.rs
|
||
|
|
+++ b/syscared/src/patch/resolver/kpatch.rs
|
||
|
|
@@ -100,8 +100,6 @@ mod ffi {
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
-use ffi::*;
|
||
|
|
-
|
||
|
|
const KPATCH_FUNCS_SECTION: &str = ".kpatch.funcs";
|
||
|
|
const KPATCH_STRINGS_SECTION: &str = ".kpatch.strings";
|
||
|
|
|
||
|
|
@@ -130,9 +128,9 @@ impl KpatchResolverImpl {
|
||
|
|
|
||
|
|
// Resolve patch functions
|
||
|
|
let patch_functions = &mut patch.functions;
|
||
|
|
- let kpatch_function_slice = object::slice_from_bytes::<KpatchFunction>(
|
||
|
|
+ let kpatch_function_slice = object::slice_from_bytes::<ffi::KpatchFunction>(
|
||
|
|
function_data,
|
||
|
|
- function_data.len() / KPATCH_FUNCTION_SIZE,
|
||
|
|
+ function_data.len() / ffi::KPATCH_FUNCTION_SIZE,
|
||
|
|
)
|
||
|
|
.map(|(f, _)| f)
|
||
|
|
.map_err(|_| anyhow!("Invalid data format"))
|
||
|
|
@@ -150,13 +148,13 @@ impl KpatchResolverImpl {
|
||
|
|
}
|
||
|
|
|
||
|
|
// Relocate patch functions
|
||
|
|
- for relocation in KpatchRelocationIterator::new(function_section.relocations()) {
|
||
|
|
+ for relocation in ffi::KpatchRelocationIterator::new(function_section.relocations()) {
|
||
|
|
let (name_reloc_offset, name_reloc) = relocation.name;
|
||
|
|
let (object_reloc_offset, obj_reloc) = relocation.object;
|
||
|
|
|
||
|
|
// Relocate patch function name
|
||
|
|
- let name_index =
|
||
|
|
- (name_reloc_offset as usize - KPATCH_FUNCTION_OFFSET) / KPATCH_FUNCTION_SIZE;
|
||
|
|
+ let name_index = (name_reloc_offset as usize - ffi::KPATCH_FUNCTION_OFFSET)
|
||
|
|
+ / ffi::KPATCH_FUNCTION_SIZE;
|
||
|
|
let name_function = patch_functions
|
||
|
|
.get_mut(name_index)
|
||
|
|
.context("Failed to find patch function")?;
|
||
|
|
@@ -168,8 +166,8 @@ impl KpatchResolverImpl {
|
||
|
|
name_function.name = name_string;
|
||
|
|
|
||
|
|
// Relocate patch function object
|
||
|
|
- let object_index =
|
||
|
|
- (object_reloc_offset as usize - KPATCH_OBJECT_OFFSET) / KPATCH_FUNCTION_SIZE;
|
||
|
|
+ let object_index = (object_reloc_offset as usize - ffi::KPATCH_OBJECT_OFFSET)
|
||
|
|
+ / ffi::KPATCH_FUNCTION_SIZE;
|
||
|
|
let object_function = patch_functions
|
||
|
|
.get_mut(object_index)
|
||
|
|
.context("Failed to find patch function")?;
|
||
|
|
diff --git a/syscared/src/patch/resolver/mod.rs b/syscared/src/patch/resolver/mod.rs
|
||
|
|
index 80e26ea..7c4a504 100644
|
||
|
|
--- a/syscared/src/patch/resolver/mod.rs
|
||
|
|
+++ b/syscared/src/patch/resolver/mod.rs
|
||
|
|
@@ -38,8 +38,8 @@ pub trait PatchResolverImpl {
|
||
|
|
pub struct PatchResolver;
|
||
|
|
|
||
|
|
impl PatchResolver {
|
||
|
|
- pub fn resolve_patch<P: AsRef<Path>>(patch_root: P) -> Result<Vec<Patch>> {
|
||
|
|
- let patch_root = patch_root.as_ref();
|
||
|
|
+ pub fn resolve_patch<P: AsRef<Path>>(directory: P) -> Result<Vec<Patch>> {
|
||
|
|
+ let patch_root = directory.as_ref();
|
||
|
|
let patch_info = Arc::new(
|
||
|
|
serde::deserialize_with_magic::<PatchInfo, _, _>(
|
||
|
|
patch_root.join(PATCH_INFO_FILE_NAME),
|
||
|
|
@@ -47,9 +47,9 @@ impl PatchResolver {
|
||
|
|
)
|
||
|
|
.context("Failed to resolve patch metadata")?,
|
||
|
|
);
|
||
|
|
- let resolver = match patch_info.kind {
|
||
|
|
- PatchType::UserPatch => &UpatchResolverImpl as &dyn PatchResolverImpl,
|
||
|
|
- PatchType::KernelPatch => &KpatchResolverImpl as &dyn PatchResolverImpl,
|
||
|
|
+ let resolver: &dyn PatchResolverImpl = match patch_info.kind {
|
||
|
|
+ PatchType::UserPatch => &UpatchResolverImpl,
|
||
|
|
+ PatchType::KernelPatch => &KpatchResolverImpl,
|
||
|
|
};
|
||
|
|
|
||
|
|
let mut patch_list = Vec::with_capacity(patch_info.entities.len());
|
||
|
|
diff --git a/syscared/src/patch/resolver/upatch.rs b/syscared/src/patch/resolver/upatch.rs
|
||
|
|
index 5df11db..cb06c24 100644
|
||
|
|
--- a/syscared/src/patch/resolver/upatch.rs
|
||
|
|
+++ b/syscared/src/patch/resolver/upatch.rs
|
||
|
|
@@ -85,8 +85,6 @@ mod ffi {
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
-use ffi::*;
|
||
|
|
-
|
||
|
|
const UPATCH_FUNCS_SECTION: &str = ".upatch.funcs";
|
||
|
|
const UPATCH_STRINGS_SECTION: &str = ".upatch.strings";
|
||
|
|
|
||
|
|
@@ -115,9 +113,9 @@ impl UpatchResolverImpl {
|
||
|
|
|
||
|
|
// Resolve patch functions
|
||
|
|
let patch_functions = &mut patch.functions;
|
||
|
|
- let upatch_function_slice = object::slice_from_bytes::<UpatchFunction>(
|
||
|
|
+ let upatch_function_slice = object::slice_from_bytes::<ffi::UpatchFunction>(
|
||
|
|
function_data,
|
||
|
|
- function_data.len() / UPATCH_FUNCTION_SIZE,
|
||
|
|
+ function_data.len() / ffi::UPATCH_FUNCTION_SIZE,
|
||
|
|
)
|
||
|
|
.map(|(f, _)| f)
|
||
|
|
.map_err(|_| anyhow!("Invalid data format"))
|
||
|
|
@@ -134,11 +132,11 @@ impl UpatchResolverImpl {
|
||
|
|
}
|
||
|
|
|
||
|
|
// Relocate patch functions
|
||
|
|
- for relocation in UpatchRelocationIterator::new(function_section.relocations()) {
|
||
|
|
+ for relocation in ffi::UpatchRelocationIterator::new(function_section.relocations()) {
|
||
|
|
let (name_reloc_offset, name_reloc) = relocation.name;
|
||
|
|
|
||
|
|
- let name_index =
|
||
|
|
- (name_reloc_offset as usize - UPATCH_FUNCTION_OFFSET) / UPATCH_FUNCTION_SIZE;
|
||
|
|
+ let name_index = (name_reloc_offset as usize - ffi::UPATCH_FUNCTION_OFFSET)
|
||
|
|
+ / ffi::UPATCH_FUNCTION_SIZE;
|
||
|
|
let name_function = patch_functions
|
||
|
|
.get_mut(name_index)
|
||
|
|
.context("Failed to find patch function")?;
|
||
|
|
diff --git a/syscared/src/rpc/skeleton_impl/patch.rs b/syscared/src/rpc/skeleton_impl/patch.rs
|
||
|
|
index b009d46..8216428 100644
|
||
|
|
--- a/syscared/src/rpc/skeleton_impl/patch.rs
|
||
|
|
+++ b/syscared/src/rpc/skeleton_impl/patch.rs
|
||
|
|
@@ -96,9 +96,10 @@ impl PatchSkeleton for PatchSkeletonImpl {
|
||
|
|
format!("Apply patch '{}'", identifier),
|
||
|
|
self.patch_manager.clone(),
|
||
|
|
PatchManager::apply_patch,
|
||
|
|
- match force {
|
||
|
|
- false => PatchOpFlag::Normal,
|
||
|
|
- true => PatchOpFlag::Force,
|
||
|
|
+ if force {
|
||
|
|
+ PatchOpFlag::Force
|
||
|
|
+ } else {
|
||
|
|
+ PatchOpFlag::Normal
|
||
|
|
},
|
||
|
|
identifier,
|
||
|
|
)
|
||
|
|
@@ -131,9 +132,10 @@ impl PatchSkeleton for PatchSkeletonImpl {
|
||
|
|
format!("Active patch '{}'", identifier),
|
||
|
|
self.patch_manager.clone(),
|
||
|
|
PatchManager::active_patch,
|
||
|
|
- match force {
|
||
|
|
- false => PatchOpFlag::Normal,
|
||
|
|
- true => PatchOpFlag::Force,
|
||
|
|
+ if force {
|
||
|
|
+ PatchOpFlag::Force
|
||
|
|
+ } else {
|
||
|
|
+ PatchOpFlag::Normal
|
||
|
|
},
|
||
|
|
identifier,
|
||
|
|
)
|
||
|
|
diff --git a/upatch-build/build.rs b/upatch-build/build.rs
|
||
|
|
index 8cbb156..9ef3a36 100644
|
||
|
|
--- a/upatch-build/build.rs
|
||
|
|
+++ b/upatch-build/build.rs
|
||
|
|
@@ -12,26 +12,25 @@
|
||
|
|
* See the Mulan PSL v2 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
-use std::{env, process::Command};
|
||
|
|
+use std::{env, ffi::OsStr, os::unix::ffi::OsStrExt, process::Command};
|
||
|
|
|
||
|
|
fn rewrite_version() {
|
||
|
|
- const ENV_VERSION_NAME: &str = "BUILD_VERSION";
|
||
|
|
- const PKG_VERSION_NAME: &str = "CARGO_PKG_VERSION";
|
||
|
|
+ const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||
|
|
+ const ENV_VERSION: Option<&str> = option_env!("BUILD_VERSION");
|
||
|
|
|
||
|
|
- let version = env::var(ENV_VERSION_NAME).unwrap_or_else(|_| {
|
||
|
|
- let pkg_version = env::var(PKG_VERSION_NAME).expect("Failed to fetch package version");
|
||
|
|
- let git_output = Command::new("git")
|
||
|
|
- .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
- .output()
|
||
|
|
- .map(|output| String::from_utf8(output.stdout).expect("Failed to fetch git version"));
|
||
|
|
-
|
||
|
|
- match git_output {
|
||
|
|
- Ok(git_version) => format!("{}-g{}", pkg_version, git_version),
|
||
|
|
- Err(_) => pkg_version,
|
||
|
|
- }
|
||
|
|
- });
|
||
|
|
-
|
||
|
|
- println!("cargo:rustc-env={}={}", PKG_VERSION_NAME, version);
|
||
|
|
+ println!(
|
||
|
|
+ "cargo:rustc-env=CARGO_PKG_VERSION={}",
|
||
|
|
+ ENV_VERSION.map(String::from).unwrap_or_else(|| {
|
||
|
|
+ Command::new("git")
|
||
|
|
+ .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
+ .output()
|
||
|
|
+ .map(|output| {
|
||
|
|
+ let git_version = OsStr::from_bytes(&output.stdout).to_string_lossy();
|
||
|
|
+ format!("{}-g{}", PKG_VERSION, git_version)
|
||
|
|
+ })
|
||
|
|
+ .unwrap_or_else(|_| PKG_VERSION.to_string())
|
||
|
|
+ })
|
||
|
|
+ );
|
||
|
|
}
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
diff --git a/upatch-build/src/args.rs b/upatch-build/src/args.rs
|
||
|
|
index c3b6f48..04790c1 100644
|
||
|
|
--- a/upatch-build/src/args.rs
|
||
|
|
+++ b/upatch-build/src/args.rs
|
||
|
|
@@ -113,13 +113,15 @@ impl Arguments {
|
||
|
|
args.name.push("-");
|
||
|
|
}
|
||
|
|
|
||
|
|
- args.elf_dir = match args.elf_dir.as_os_str().is_empty() {
|
||
|
|
- false => fs::normalize(&args.elf_dir)?,
|
||
|
|
- true => args.source_dir.clone(),
|
||
|
|
+ args.elf_dir = if args.elf_dir.as_os_str().is_empty() {
|
||
|
|
+ args.source_dir.clone()
|
||
|
|
+ } else {
|
||
|
|
+ fs::normalize(&args.elf_dir)?
|
||
|
|
};
|
||
|
|
- args.object_dir = match args.object_dir.as_os_str().is_empty() {
|
||
|
|
- false => fs::normalize(&args.object_dir)?,
|
||
|
|
- true => args.source_dir.clone(),
|
||
|
|
+ args.object_dir = if args.object_dir.as_os_str().is_empty() {
|
||
|
|
+ args.source_dir.clone()
|
||
|
|
+ } else {
|
||
|
|
+ fs::normalize(&args.object_dir)?
|
||
|
|
};
|
||
|
|
|
||
|
|
for elf_path in &mut args.elf {
|
||
|
|
diff --git a/upatch-build/src/build_root.rs b/upatch-build/src/build_root.rs
|
||
|
|
index 556231d..5915bbc 100644
|
||
|
|
--- a/upatch-build/src/build_root.rs
|
||
|
|
+++ b/upatch-build/src/build_root.rs
|
||
|
|
@@ -26,8 +26,8 @@ pub struct BuildRoot {
|
||
|
|
}
|
||
|
|
|
||
|
|
impl BuildRoot {
|
||
|
|
- pub fn new<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||
|
|
- let path = path.as_ref().to_path_buf();
|
||
|
|
+ pub fn new<P: AsRef<Path>>(directory: P) -> Result<Self> {
|
||
|
|
+ let path = directory.as_ref().to_path_buf();
|
||
|
|
let original_dir = path.join("original");
|
||
|
|
let patched_dir = path.join("patched");
|
||
|
|
let temp_dir = path.join("temp");
|
||
|
|
diff --git a/upatch-build/src/compiler.rs b/upatch-build/src/compiler.rs
|
||
|
|
index 7778f0b..b4866bd 100644
|
||
|
|
--- a/upatch-build/src/compiler.rs
|
||
|
|
+++ b/upatch-build/src/compiler.rs
|
||
|
|
@@ -178,23 +178,28 @@ impl Compiler {
|
||
|
|
let mut result = Vec::new();
|
||
|
|
|
||
|
|
for compiler in compilers {
|
||
|
|
- let compiler = compiler.as_ref();
|
||
|
|
- let compiler_name = compiler
|
||
|
|
+ let compiler_path = compiler.as_ref();
|
||
|
|
+ let compiler_name = compiler_path
|
||
|
|
.file_name()
|
||
|
|
.context("Failed to parse compiler name")?;
|
||
|
|
|
||
|
|
let output_dir = temp_dir.as_ref().join(compiler_name);
|
||
|
|
fs::create_dir_all(&output_dir)?;
|
||
|
|
|
||
|
|
- debug!("- Checking {}", compiler.display());
|
||
|
|
- let assembler_name =
|
||
|
|
- Self::get_component_name(compiler, ASSEMBLER_NAME).with_context(|| {
|
||
|
|
- format!("Failed to get assembler name of {}", compiler.display())
|
||
|
|
+ debug!("- Checking {}", compiler_path.display());
|
||
|
|
+ let assembler_name = Self::get_component_name(compiler_path, ASSEMBLER_NAME)
|
||
|
|
+ .with_context(|| {
|
||
|
|
+ format!(
|
||
|
|
+ "Failed to get assembler name of {}",
|
||
|
|
+ compiler_path.display()
|
||
|
|
+ )
|
||
|
|
+ })?;
|
||
|
|
+ let linker_name =
|
||
|
|
+ Self::get_component_name(compiler_path, LINKER_NAME).with_context(|| {
|
||
|
|
+ format!("Failed to get linker name of {}", compiler_path.display())
|
||
|
|
})?;
|
||
|
|
- let linker_name = Self::get_component_name(compiler, LINKER_NAME)
|
||
|
|
- .with_context(|| format!("Failed to get linker name of {}", compiler.display()))?;
|
||
|
|
|
||
|
|
- let path = compiler.to_path_buf();
|
||
|
|
+ let path = compiler_path.to_path_buf();
|
||
|
|
let assembler = which(assembler_name.trim()).with_context(|| {
|
||
|
|
format!("Cannot find assembler {}", assembler_name.to_string_lossy())
|
||
|
|
})?;
|
||
|
|
@@ -202,17 +207,17 @@ impl Compiler {
|
||
|
|
.with_context(|| format!("Cannot find linker {}", linker_name.to_string_lossy()))?;
|
||
|
|
let versions = IndexSet::new();
|
||
|
|
|
||
|
|
- let mut compiler = Self {
|
||
|
|
+ let mut instance = Self {
|
||
|
|
path,
|
||
|
|
assembler,
|
||
|
|
linker,
|
||
|
|
versions,
|
||
|
|
};
|
||
|
|
- compiler
|
||
|
|
+ instance
|
||
|
|
.fetch_versions(output_dir)
|
||
|
|
.context("Failed to fetch supported versions")?;
|
||
|
|
|
||
|
|
- result.push(compiler);
|
||
|
|
+ result.push(instance);
|
||
|
|
}
|
||
|
|
|
||
|
|
Ok(result)
|
||
|
|
diff --git a/upatch-build/src/dwarf/mod.rs b/upatch-build/src/dwarf/mod.rs
|
||
|
|
index 35f359e..6a91f7c 100644
|
||
|
|
--- a/upatch-build/src/dwarf/mod.rs
|
||
|
|
+++ b/upatch-build/src/dwarf/mod.rs
|
||
|
|
@@ -49,9 +49,9 @@ pub struct CompileUnit {
|
||
|
|
pub struct Dwarf;
|
||
|
|
|
||
|
|
impl Dwarf {
|
||
|
|
- pub fn parse<P: AsRef<Path>>(elf: P) -> Result<Vec<CompileUnit>> {
|
||
|
|
+ pub fn parse<P: AsRef<Path>>(file_path: P) -> Result<Vec<CompileUnit>> {
|
||
|
|
// use mmap here, but depend on some devices
|
||
|
|
- let elf = elf.as_ref();
|
||
|
|
+ let elf = file_path.as_ref();
|
||
|
|
let file = std::fs::File::open(elf)?;
|
||
|
|
let mmap = unsafe { memmap2::Mmap::map(&file)? };
|
||
|
|
|
||
|
|
@@ -88,6 +88,8 @@ impl Dwarf {
|
||
|
|
file: &File,
|
||
|
|
section: &Section,
|
||
|
|
) {
|
||
|
|
+ const INVALID_SECTION_NAME: &str = ".invalid";
|
||
|
|
+
|
||
|
|
for (offset64, mut relocation) in section.relocations() {
|
||
|
|
let offset = offset64 as usize;
|
||
|
|
if offset as u64 != offset64 {
|
||
|
|
@@ -104,8 +106,7 @@ impl Dwarf {
|
||
|
|
}
|
||
|
|
Err(_) => {
|
||
|
|
trace!("Relocation with invalid symbol for section {} at offset 0x{:08x}",
|
||
|
|
- section.name().unwrap(),
|
||
|
|
- offset
|
||
|
|
+ section.name().unwrap_or(INVALID_SECTION_NAME), offset
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@@ -113,7 +114,7 @@ impl Dwarf {
|
||
|
|
if relocations.insert(offset, relocation).is_some() {
|
||
|
|
trace!(
|
||
|
|
"Multiple relocations for section {} at offset 0x{:08x}",
|
||
|
|
- section.name().unwrap(),
|
||
|
|
+ section.name().unwrap_or(INVALID_SECTION_NAME),
|
||
|
|
offset
|
||
|
|
);
|
||
|
|
}
|
||
|
|
@@ -121,7 +122,7 @@ impl Dwarf {
|
||
|
|
_ => {
|
||
|
|
trace!(
|
||
|
|
"Unsupported relocation for section {} at offset 0x{:08x}",
|
||
|
|
- section.name().unwrap(),
|
||
|
|
+ section.name().unwrap_or(INVALID_SECTION_NAME),
|
||
|
|
offset
|
||
|
|
);
|
||
|
|
}
|
||
|
|
@@ -136,12 +137,12 @@ impl Dwarf {
|
||
|
|
arena_data: &'arena Arena<Cow<'input, [u8]>>,
|
||
|
|
arena_relocations: &'arena Arena<IndexMap<usize, Relocation>>,
|
||
|
|
) -> Result<Relocate<'arena, EndianSlice<'arena, Endian>>> {
|
||
|
|
- let mut relocations = IndexMap::new();
|
||
|
|
+ let mut relocation_map = IndexMap::new();
|
||
|
|
let name = Some(id.name());
|
||
|
|
- let data = match name.and_then(|name| file.section_by_name(name)) {
|
||
|
|
+ let data = match name.and_then(|section_name| file.section_by_name(section_name)) {
|
||
|
|
Some(ref section) => {
|
||
|
|
// DWO sections never have relocations, so don't bother.
|
||
|
|
- Self::add_relocations(&mut relocations, file, section);
|
||
|
|
+ Self::add_relocations(&mut relocation_map, file, section);
|
||
|
|
section.uncompressed_data()?
|
||
|
|
}
|
||
|
|
// Use a non-zero capacity so that `ReaderOffsetId`s are unique.
|
||
|
|
@@ -150,7 +151,7 @@ impl Dwarf {
|
||
|
|
let data_ref = (*arena_data.alloc(data)).borrow();
|
||
|
|
let reader = EndianSlice::new(data_ref, endian);
|
||
|
|
let section = reader;
|
||
|
|
- let relocations = (*arena_relocations.alloc(relocations)).borrow();
|
||
|
|
+ let relocations = (*arena_relocations.alloc(relocation_map)).borrow();
|
||
|
|
Ok(Relocate {
|
||
|
|
relocations,
|
||
|
|
section,
|
||
|
|
diff --git a/upatch-build/src/dwarf/relocate.rs b/upatch-build/src/dwarf/relocate.rs
|
||
|
|
index 2a6e393..e8c7cdf 100644
|
||
|
|
--- a/upatch-build/src/dwarf/relocate.rs
|
||
|
|
+++ b/upatch-build/src/dwarf/relocate.rs
|
||
|
|
@@ -14,6 +14,7 @@
|
||
|
|
|
||
|
|
use std::borrow::Cow;
|
||
|
|
|
||
|
|
+use gimli::ReaderOffset;
|
||
|
|
use indexmap::IndexMap;
|
||
|
|
use object::Relocation;
|
||
|
|
|
||
|
|
@@ -28,10 +29,11 @@ impl<'a, R: gimli::Reader<Offset = usize>> Relocate<'a, R> {
|
||
|
|
pub fn relocate(&self, offset: usize, value: u64) -> u64 {
|
||
|
|
if let Some(relocation) = self.relocations.get(&offset) {
|
||
|
|
if relocation.kind() == object::RelocationKind::Absolute {
|
||
|
|
- return match relocation.has_implicit_addend() {
|
||
|
|
+ return if relocation.has_implicit_addend() {
|
||
|
|
// Use the explicit addend too, because it may have the symbol value.
|
||
|
|
- true => value.wrapping_add(relocation.addend() as u64),
|
||
|
|
- false => relocation.addend() as u64,
|
||
|
|
+ value.wrapping_add(relocation.addend() as u64)
|
||
|
|
+ } else {
|
||
|
|
+ relocation.addend() as u64
|
||
|
|
};
|
||
|
|
}
|
||
|
|
};
|
||
|
|
@@ -52,19 +54,19 @@ impl<'a, R: gimli::Reader<Offset = usize>> gimli::Reader for Relocate<'a, R> {
|
||
|
|
fn read_length(&mut self, format: gimli::Format) -> gimli::Result<usize> {
|
||
|
|
let offset = self.reader.offset_from(&self.section);
|
||
|
|
let value = self.reader.read_length(format)?;
|
||
|
|
- <usize as gimli::ReaderOffset>::from_u64(self.relocate(offset, value as u64))
|
||
|
|
+ gimli::ReaderOffset::from_u64(self.relocate(offset, value.into_u64()))
|
||
|
|
}
|
||
|
|
|
||
|
|
fn read_offset(&mut self, format: gimli::Format) -> gimli::Result<usize> {
|
||
|
|
let offset = self.reader.offset_from(&self.section);
|
||
|
|
let value = self.reader.read_offset(format)?;
|
||
|
|
- <usize as gimli::ReaderOffset>::from_u64(self.relocate(offset, value as u64))
|
||
|
|
+ gimli::ReaderOffset::from_u64(self.relocate(offset, value.into_u64()))
|
||
|
|
}
|
||
|
|
|
||
|
|
fn read_sized_offset(&mut self, size: u8) -> gimli::Result<usize> {
|
||
|
|
let offset = self.reader.offset_from(&self.section);
|
||
|
|
let value = self.reader.read_sized_offset(size)?;
|
||
|
|
- <usize as gimli::ReaderOffset>::from_u64(self.relocate(offset, value as u64))
|
||
|
|
+ gimli::ReaderOffset::from_u64(self.relocate(offset, value.into_u64()))
|
||
|
|
}
|
||
|
|
|
||
|
|
#[inline]
|
||
|
|
diff --git a/upatch-build/src/elf/header.rs b/upatch-build/src/elf/header.rs
|
||
|
|
index ad9f8fd..a4c4ca8 100644
|
||
|
|
--- a/upatch-build/src/elf/header.rs
|
||
|
|
+++ b/upatch-build/src/elf/header.rs
|
||
|
|
@@ -48,10 +48,6 @@ pub trait HeaderWrite: OperateWrite {
|
||
|
|
fn set_e_ident(&mut self, e_ident: u128) {
|
||
|
|
self.set(offset_of!(FileHeader64, e_ident), e_ident)
|
||
|
|
}
|
||
|
|
-
|
||
|
|
- fn set_e_shnum(&mut self, e_shnum: u16) {
|
||
|
|
- self.set(offset_of!(FileHeader64, e_shnum), e_shnum)
|
||
|
|
- }
|
||
|
|
}
|
||
|
|
|
||
|
|
#[repr(C)]
|
||
|
|
diff --git a/upatch-build/src/elf/read/elfs.rs b/upatch-build/src/elf/read/elfs.rs
|
||
|
|
index 11d57e3..52c5e6b 100644
|
||
|
|
--- a/upatch-build/src/elf/read/elfs.rs
|
||
|
|
+++ b/upatch-build/src/elf/read/elfs.rs
|
||
|
|
@@ -19,10 +19,10 @@ use anyhow::bail;
|
||
|
|
use anyhow::Result;
|
||
|
|
use memmap2::{Mmap, MmapOptions};
|
||
|
|
|
||
|
|
-use super::super::*;
|
||
|
|
-use super::Header;
|
||
|
|
-use super::SectionHeaderTable;
|
||
|
|
-use super::SymbolHeaderTable;
|
||
|
|
+use super::{
|
||
|
|
+ super::{check_elf, check_header, Endian, HeaderRead, SectionRead, SymbolHeader64, SHT_SYMTAB},
|
||
|
|
+ Header, SectionHeaderTable, SymbolHeaderTable,
|
||
|
|
+};
|
||
|
|
|
||
|
|
#[derive(Debug)]
|
||
|
|
pub struct Elf {
|
||
|
|
@@ -61,7 +61,7 @@ impl Elf {
|
||
|
|
|
||
|
|
pub fn symbols(&self) -> Result<SymbolHeaderTable> {
|
||
|
|
let sections = self.sections()?;
|
||
|
|
- for section in sections {
|
||
|
|
+ for section in sections.clone() {
|
||
|
|
if section.get_sh_type().eq(&SHT_SYMTAB) {
|
||
|
|
let offset = section.get_sh_offset() as usize;
|
||
|
|
let size_sum = section.get_sh_size() as usize;
|
||
|
|
diff --git a/upatch-build/src/elf/read/section.rs b/upatch-build/src/elf/read/section.rs
|
||
|
|
index a12c4f3..8f79c8b 100644
|
||
|
|
--- a/upatch-build/src/elf/read/section.rs
|
||
|
|
+++ b/upatch-build/src/elf/read/section.rs
|
||
|
|
@@ -44,7 +44,7 @@ impl OperateRead for SectionHeader<'_> {
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
-#[derive(Debug, Clone, Copy)]
|
||
|
|
+#[derive(Debug, Clone)]
|
||
|
|
pub struct SectionHeaderTable<'a> {
|
||
|
|
mmap: &'a Mmap,
|
||
|
|
endian: Endian,
|
||
|
|
@@ -86,16 +86,13 @@ impl<'a> Iterator for SectionHeaderTable<'a> {
|
||
|
|
type Item = SectionHeader<'a>;
|
||
|
|
|
||
|
|
fn next(&mut self) -> Option<Self::Item> {
|
||
|
|
- match self.count < self.num {
|
||
|
|
- true => {
|
||
|
|
- let offset = self.count * self.size + self.offset;
|
||
|
|
- self.count += 1;
|
||
|
|
- Some(SectionHeader::from(self.mmap, self.endian, offset))
|
||
|
|
- }
|
||
|
|
- false => {
|
||
|
|
- self.count = 0;
|
||
|
|
- None
|
||
|
|
- }
|
||
|
|
+ if self.count < self.num {
|
||
|
|
+ let offset = self.count * self.size + self.offset;
|
||
|
|
+ self.count += 1;
|
||
|
|
+ Some(SectionHeader::from(self.mmap, self.endian, offset))
|
||
|
|
+ } else {
|
||
|
|
+ self.count = 0;
|
||
|
|
+ None
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
diff --git a/upatch-build/src/elf/read/symbol.rs b/upatch-build/src/elf/read/symbol.rs
|
||
|
|
index 70f03e1..0c05cb6 100644
|
||
|
|
--- a/upatch-build/src/elf/read/symbol.rs
|
||
|
|
+++ b/upatch-build/src/elf/read/symbol.rs
|
||
|
|
@@ -99,9 +99,10 @@ impl<'a> SymbolHeaderTable<'a> {
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn reset(&mut self, n: usize) {
|
||
|
|
- match n < self.num {
|
||
|
|
- true => self.count = n,
|
||
|
|
- false => self.count = 0,
|
||
|
|
+ if n < self.num {
|
||
|
|
+ self.count = n;
|
||
|
|
+ } else {
|
||
|
|
+ self.count = 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@@ -110,21 +111,18 @@ impl<'a> Iterator for SymbolHeaderTable<'a> {
|
||
|
|
type Item = SymbolHeader<'a>;
|
||
|
|
|
||
|
|
fn next(&mut self) -> Option<Self::Item> {
|
||
|
|
- match self.count < self.num {
|
||
|
|
- true => {
|
||
|
|
- let offset = self.count * self.size + self.offset;
|
||
|
|
- self.count += 1;
|
||
|
|
- Some(SymbolHeader::from(
|
||
|
|
- self.mmap,
|
||
|
|
- self.endian,
|
||
|
|
- self.strtab,
|
||
|
|
- offset,
|
||
|
|
- ))
|
||
|
|
- }
|
||
|
|
- false => {
|
||
|
|
- self.count = 0;
|
||
|
|
- None
|
||
|
|
- }
|
||
|
|
+ if self.count < self.num {
|
||
|
|
+ let offset = self.count * self.size + self.offset;
|
||
|
|
+ self.count += 1;
|
||
|
|
+ Some(SymbolHeader::from(
|
||
|
|
+ self.mmap,
|
||
|
|
+ self.endian,
|
||
|
|
+ self.strtab,
|
||
|
|
+ offset,
|
||
|
|
+ ))
|
||
|
|
+ } else {
|
||
|
|
+ self.count = 0;
|
||
|
|
+ None
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
diff --git a/upatch-build/src/elf/write/elfs.rs b/upatch-build/src/elf/write/elfs.rs
|
||
|
|
index e41ad0f..9ce2847 100644
|
||
|
|
--- a/upatch-build/src/elf/write/elfs.rs
|
||
|
|
+++ b/upatch-build/src/elf/write/elfs.rs
|
||
|
|
@@ -15,11 +15,13 @@
|
||
|
|
use std::fs::{File, OpenOptions};
|
||
|
|
use std::path::Path;
|
||
|
|
|
||
|
|
-use anyhow::{bail, Result};
|
||
|
|
+use anyhow::{bail, Context, Result};
|
||
|
|
use memmap2::{Mmap, MmapOptions};
|
||
|
|
|
||
|
|
-use super::super::*;
|
||
|
|
-use super::{Header, SectionHeader, SymbolHeaderTable};
|
||
|
|
+use super::{
|
||
|
|
+ super::{check_elf, check_header, Endian, HeaderRead, SectionRead, SymbolHeader64, SHT_SYMTAB},
|
||
|
|
+ Header, SectionHeader, SymbolHeaderTable,
|
||
|
|
+};
|
||
|
|
|
||
|
|
#[derive(Debug)]
|
||
|
|
pub struct Elf {
|
||
|
|
@@ -88,7 +90,7 @@ impl Elf {
|
||
|
|
return Ok(SymbolHeaderTable::from(
|
||
|
|
&self.file,
|
||
|
|
self.endian,
|
||
|
|
- self.strtab.as_ref().unwrap(),
|
||
|
|
+ self.strtab.as_ref().context("Invalid strtab")?,
|
||
|
|
offset,
|
||
|
|
size,
|
||
|
|
offset + size_sum,
|
||
|
|
diff --git a/upatch-build/src/elf/write/symbol.rs b/upatch-build/src/elf/write/symbol.rs
|
||
|
|
index 5946897..0a2d08a 100644
|
||
|
|
--- a/upatch-build/src/elf/write/symbol.rs
|
||
|
|
+++ b/upatch-build/src/elf/write/symbol.rs
|
||
|
|
@@ -38,13 +38,12 @@ impl<'a> SymbolHeader<'a> {
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn get_st_name(&mut self) -> &OsStr {
|
||
|
|
- match self.name.is_empty() {
|
||
|
|
- false => <&std::ffi::OsStr>::clone(&self.name),
|
||
|
|
- true => {
|
||
|
|
- let name_offset = self.get_st_name_offset() as usize;
|
||
|
|
- self.name = self.read_to_os_string(name_offset);
|
||
|
|
- self.name
|
||
|
|
- }
|
||
|
|
+ if !self.name.is_empty() {
|
||
|
|
+ self.name
|
||
|
|
+ } else {
|
||
|
|
+ let name_offset = self.get_st_name_offset() as usize;
|
||
|
|
+ self.name = self.read_to_os_string(name_offset);
|
||
|
|
+ self.name
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@@ -120,22 +119,19 @@ impl<'a> Iterator for SymbolHeaderTable<'a> {
|
||
|
|
|
||
|
|
fn next(&mut self) -> Option<Self::Item> {
|
||
|
|
let offset = self.count * self.size + self.start;
|
||
|
|
- match offset < self.end {
|
||
|
|
- true => {
|
||
|
|
- self.count += 1;
|
||
|
|
- let mmap = unsafe {
|
||
|
|
- MmapOptions::new()
|
||
|
|
- .offset(offset as u64)
|
||
|
|
- .len(self.size)
|
||
|
|
- .map_mut(self.file)
|
||
|
|
- .unwrap()
|
||
|
|
- };
|
||
|
|
- Some(SymbolHeader::from(mmap, self.endian, self.strtab))
|
||
|
|
- }
|
||
|
|
- false => {
|
||
|
|
- self.count = 0;
|
||
|
|
- None
|
||
|
|
+ if offset < self.end {
|
||
|
|
+ self.count += 1;
|
||
|
|
+ unsafe {
|
||
|
|
+ MmapOptions::new()
|
||
|
|
+ .offset(offset as u64)
|
||
|
|
+ .len(self.size)
|
||
|
|
+ .map_mut(self.file)
|
||
|
|
+ .ok()
|
||
|
|
+ .map(|mmap_mut| SymbolHeader::from(mmap_mut, self.endian, self.strtab))
|
||
|
|
}
|
||
|
|
+ } else {
|
||
|
|
+ self.count = 0;
|
||
|
|
+ None
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
diff --git a/upatch-build/src/file_relation.rs b/upatch-build/src/file_relation.rs
|
||
|
|
index 5a58d04..eedd7d8 100644
|
||
|
|
--- a/upatch-build/src/file_relation.rs
|
||
|
|
+++ b/upatch-build/src/file_relation.rs
|
||
|
|
@@ -60,14 +60,14 @@ impl FileRelation {
|
||
|
|
P: AsRef<Path>,
|
||
|
|
Q: AsRef<Path>,
|
||
|
|
{
|
||
|
|
- let mut binaries = binaries.into_iter();
|
||
|
|
- let mut debuginfos = debuginfos.into_iter();
|
||
|
|
+ let mut binary_iter = binaries.into_iter();
|
||
|
|
+ let mut debuginfo_iter = debuginfos.into_iter();
|
||
|
|
|
||
|
|
- while let (Some(binary), Some(debuginfo)) = (binaries.next(), debuginfos.next()) {
|
||
|
|
- let binary = Self::find_binary_file(binary)?;
|
||
|
|
- let debuginfo = debuginfo.as_ref().to_path_buf();
|
||
|
|
+ while let (Some(binary), Some(debuginfo)) = (binary_iter.next(), debuginfo_iter.next()) {
|
||
|
|
+ let binary_file = Self::find_binary_file(binary)?;
|
||
|
|
+ let debuginfo_file = debuginfo.as_ref().to_path_buf();
|
||
|
|
|
||
|
|
- self.debuginfo_map.insert(binary, debuginfo);
|
||
|
|
+ self.debuginfo_map.insert(binary_file, debuginfo_file);
|
||
|
|
}
|
||
|
|
|
||
|
|
Ok(())
|
||
|
|
diff --git a/upatch-build/src/main.rs b/upatch-build/src/main.rs
|
||
|
|
index 769cc6c..5aefd73 100644
|
||
|
|
--- a/upatch-build/src/main.rs
|
||
|
|
+++ b/upatch-build/src/main.rs
|
||
|
|
@@ -333,9 +333,10 @@ impl UpatchBuild {
|
||
|
|
let binary_name = binary
|
||
|
|
.file_name()
|
||
|
|
.with_context(|| format!("Failed to parse binary name of {}", binary.display()))?;
|
||
|
|
- let patch_name = match name.is_empty() {
|
||
|
|
- true => binary_name.to_os_string(),
|
||
|
|
- false => concat_os!(name, "-", binary_name),
|
||
|
|
+ let patch_name = if name.is_empty() {
|
||
|
|
+ binary_name.to_os_string()
|
||
|
|
+ } else {
|
||
|
|
+ concat_os!(name, "-", binary_name)
|
||
|
|
};
|
||
|
|
let output_file = build_info.output_dir.join(&patch_name);
|
||
|
|
|
||
|
|
@@ -393,11 +394,10 @@ impl UpatchBuild {
|
||
|
|
.context("Patch test failed")?;
|
||
|
|
|
||
|
|
info!("Checking debuginfo version(s)");
|
||
|
|
- match self.args.skip_compiler_check {
|
||
|
|
- false => {
|
||
|
|
- Self::check_debuginfo(&compilers, debuginfos).context("Debuginfo check failed")?;
|
||
|
|
- }
|
||
|
|
- true => warn!("Warning: Skipped compiler version check!"),
|
||
|
|
+ if self.args.skip_compiler_check {
|
||
|
|
+ warn!("Warning: Skipped compiler version check!")
|
||
|
|
+ } else {
|
||
|
|
+ Self::check_debuginfo(&compilers, debuginfos).context("Debuginfo check failed")?;
|
||
|
|
}
|
||
|
|
|
||
|
|
let mut files = FileRelation::new();
|
||
|
|
diff --git a/upatch-build/src/pattern_path.rs b/upatch-build/src/pattern_path.rs
|
||
|
|
index 4ef86e1..f468620 100644
|
||
|
|
--- a/upatch-build/src/pattern_path.rs
|
||
|
|
+++ b/upatch-build/src/pattern_path.rs
|
||
|
|
@@ -40,22 +40,18 @@ pub fn glob<P: AsRef<Path>>(path: P) -> std::io::Result<Vec<PathBuf>> {
|
||
|
|
let mut path_clone = vec![];
|
||
|
|
for p in &mut pathes {
|
||
|
|
let tmp = p.join(components[i]);
|
||
|
|
- match tmp.exists() {
|
||
|
|
- true => path_clone.push(tmp),
|
||
|
|
- false => {
|
||
|
|
- let all_pathes = match i == (components.len() - 1) {
|
||
|
|
- true => {
|
||
|
|
- fs::list_files(&p, fs::TraverseOptions { recursive: false })
|
||
|
|
- }
|
||
|
|
- false => {
|
||
|
|
- fs::list_dirs(&p, fs::TraverseOptions { recursive: false })
|
||
|
|
- }
|
||
|
|
- }?;
|
||
|
|
- for name in find_name(components[i].as_os_str(), all_pathes)? {
|
||
|
|
- path_clone.push(p.join(name));
|
||
|
|
- }
|
||
|
|
+ if tmp.exists() {
|
||
|
|
+ path_clone.push(tmp);
|
||
|
|
+ } else {
|
||
|
|
+ let all_pathes = if i == (components.len() - 1) {
|
||
|
|
+ fs::list_files(&p, fs::TraverseOptions { recursive: false })
|
||
|
|
+ } else {
|
||
|
|
+ fs::list_dirs(&p, fs::TraverseOptions { recursive: false })
|
||
|
|
+ }?;
|
||
|
|
+ for name in find_name(components[i].as_os_str(), all_pathes)? {
|
||
|
|
+ path_clone.push(p.join(name));
|
||
|
|
}
|
||
|
|
- };
|
||
|
|
+ }
|
||
|
|
}
|
||
|
|
pathes = path_clone;
|
||
|
|
}
|
||
|
|
diff --git a/upatch-build/src/resolve.rs b/upatch-build/src/resolve.rs
|
||
|
|
index 58947c0..d579901 100644
|
||
|
|
--- a/upatch-build/src/resolve.rs
|
||
|
|
+++ b/upatch-build/src/resolve.rs
|
||
|
|
@@ -17,19 +17,19 @@ use std::path::Path;
|
||
|
|
use anyhow::Result;
|
||
|
|
use log::trace;
|
||
|
|
|
||
|
|
-use crate::elf::*;
|
||
|
|
+use crate::elf::{self, HeaderRead, HeaderWrite, SymbolRead, SymbolWrite};
|
||
|
|
|
||
|
|
pub fn resolve_upatch<P, Q>(patch: Q, debuginfo: P) -> Result<()>
|
||
|
|
where
|
||
|
|
P: AsRef<Path>,
|
||
|
|
Q: AsRef<Path>,
|
||
|
|
{
|
||
|
|
- let mut patch_elf = write::Elf::parse(patch)?;
|
||
|
|
- let debuginfo_elf = read::Elf::parse(debuginfo)?;
|
||
|
|
+ let mut patch_elf = elf::write::Elf::parse(patch)?;
|
||
|
|
+ let debuginfo_elf = elf::read::Elf::parse(debuginfo)?;
|
||
|
|
|
||
|
|
let debuginfo_e_ident = debuginfo_elf.header()?.get_e_ident();
|
||
|
|
let debuginfo_e_type = debuginfo_elf.header()?.get_e_type();
|
||
|
|
- let ei_osabi = elf_ei_osabi(debuginfo_e_ident);
|
||
|
|
+ let ei_osabi = elf::elf_ei_osabi(debuginfo_e_ident);
|
||
|
|
|
||
|
|
patch_elf.header()?.set_e_ident(debuginfo_e_ident);
|
||
|
|
|
||
|
|
@@ -37,28 +37,29 @@ where
|
||
|
|
|
||
|
|
for mut symbol in &mut patch_elf.symbols()? {
|
||
|
|
/* No need to handle section symbol */
|
||
|
|
- let sym_info = symbol.get_st_info();
|
||
|
|
- if elf_st_type(sym_info) == STT_SECTION {
|
||
|
|
+ let sym_st_info = symbol.get_st_info();
|
||
|
|
+ if elf::elf_st_type(sym_st_info) == elf::STT_SECTION {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
let sym_other = symbol.get_st_other();
|
||
|
|
- if sym_other & SYM_OTHER != 0 {
|
||
|
|
+ if sym_other & elf::SYM_OTHER != 0 {
|
||
|
|
// TODO: we can delete these symbol's section here.
|
||
|
|
- symbol.set_st_other(sym_other & !SYM_OTHER);
|
||
|
|
+ symbol.set_st_other(sym_other & !elf::SYM_OTHER);
|
||
|
|
match symbol.get_st_value() {
|
||
|
|
- 0 => symbol.set_st_shndx(SHN_UNDEF),
|
||
|
|
- _ => symbol.set_st_shndx(SHN_LIVEPATCH),
|
||
|
|
+ 0 => symbol.set_st_shndx(elf::SHN_UNDEF),
|
||
|
|
+ _ => symbol.set_st_shndx(elf::SHN_LIVEPATCH),
|
||
|
|
};
|
||
|
|
- } else if symbol.get_st_shndx() == SHN_UNDEF {
|
||
|
|
- if elf_st_bind(sym_info) == STB_LOCAL {
|
||
|
|
+ } else if symbol.get_st_shndx() == elf::SHN_UNDEF {
|
||
|
|
+ if elf::elf_st_bind(sym_st_info) == elf::STB_LOCAL {
|
||
|
|
/* only partly resolved undefined symbol could have st_value */
|
||
|
|
if symbol.get_st_value() != 0 {
|
||
|
|
- symbol.set_st_shndx(SHN_LIVEPATCH);
|
||
|
|
+ symbol.set_st_shndx(elf::SHN_LIVEPATCH);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
__partial_resolve_patch(&mut symbol, debuginfo_syms, ei_osabi)?;
|
||
|
|
}
|
||
|
|
+ } else { /* do nothing */
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
@@ -66,21 +67,20 @@ where
|
||
|
|
* Such code accesses all constant addresses through a global offset table (GOT).
|
||
|
|
* TODO: consider check PIE
|
||
|
|
*/
|
||
|
|
- let sym_info = symbol.get_st_info();
|
||
|
|
- if debuginfo_e_type == ET_DYN
|
||
|
|
- && elf_st_bind(sym_info) == STB_GLOBAL
|
||
|
|
- && elf_st_type(sym_info) == STT_OBJECT
|
||
|
|
- && symbol.get_st_shndx() == SHN_LIVEPATCH
|
||
|
|
+ if debuginfo_e_type == elf::ET_DYN
|
||
|
|
+ && elf::elf_st_bind(sym_st_info) == elf::STB_GLOBAL
|
||
|
|
+ && elf::elf_st_type(sym_st_info) == elf::STT_OBJECT
|
||
|
|
+ && symbol.get_st_shndx() == elf::SHN_LIVEPATCH
|
||
|
|
{
|
||
|
|
- symbol.set_st_shndx(SHN_UNDEF);
|
||
|
|
+ symbol.set_st_shndx(elf::SHN_UNDEF);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
|
||
|
|
fn __partial_resolve_patch(
|
||
|
|
- symbol: &mut write::SymbolHeader,
|
||
|
|
- debuginfo_syms: &mut read::SymbolHeaderTable,
|
||
|
|
+ symbol: &mut elf::write::SymbolHeader,
|
||
|
|
+ debuginfo_syms: &mut elf::read::SymbolHeaderTable,
|
||
|
|
ei_osabi: u8,
|
||
|
|
) -> Result<()> {
|
||
|
|
debuginfo_syms.reset(0);
|
||
|
|
@@ -88,28 +88,29 @@ fn __partial_resolve_patch(
|
||
|
|
for debuginfo_sym in debuginfo_syms {
|
||
|
|
/* No need to handle section symbol */
|
||
|
|
let sym_info = debuginfo_sym.get_st_info();
|
||
|
|
- if elf_st_type(sym_info) == STT_SECTION {
|
||
|
|
+ if elf::elf_st_type(sym_info) == elf::STT_SECTION {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
let debuginfo_name = debuginfo_sym.get_st_name();
|
||
|
|
- if elf_st_bind(sym_info).ne(&elf_st_bind(symbol.get_st_info()))
|
||
|
|
+ if elf::elf_st_bind(sym_info).ne(&elf::elf_st_bind(symbol.get_st_info()))
|
||
|
|
|| debuginfo_name.ne(symbol.get_st_name())
|
||
|
|
{
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* leave it to be handled in running time */
|
||
|
|
- if debuginfo_sym.get_st_shndx() == SHN_UNDEF {
|
||
|
|
+ if debuginfo_sym.get_st_shndx() == elf::SHN_UNDEF {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
// symbol type is STT_IFUNC, need search st_value in .plt table in upatch.
|
||
|
|
- let is_ifunc = (ei_osabi.eq(&ELFOSABI_GNU) || ei_osabi.eq(&ELFOSABI_FREEBSD))
|
||
|
|
- && elf_st_type(sym_info).eq(&STT_IFUNC);
|
||
|
|
- symbol.set_st_shndx(match is_ifunc {
|
||
|
|
- true => SHN_UNDEF,
|
||
|
|
- false => SHN_LIVEPATCH,
|
||
|
|
+ let is_ifunc = (ei_osabi.eq(&elf::ELFOSABI_GNU) || ei_osabi.eq(&elf::ELFOSABI_FREEBSD))
|
||
|
|
+ && elf::elf_st_type(sym_info).eq(&elf::STT_IFUNC);
|
||
|
|
+ symbol.set_st_shndx(if is_ifunc {
|
||
|
|
+ elf::SHN_UNDEF
|
||
|
|
+ } else {
|
||
|
|
+ elf::SHN_LIVEPATCH
|
||
|
|
});
|
||
|
|
symbol.set_st_info(sym_info);
|
||
|
|
symbol.set_st_other(debuginfo_sym.get_st_other());
|
||
|
|
@@ -131,17 +132,17 @@ fn __partial_resolve_patch(
|
||
|
|
* then we can't match these symbols, we change these symbols to GLOBAL here.
|
||
|
|
*/
|
||
|
|
pub fn resolve_dynamic<P: AsRef<Path>>(debuginfo: P) -> Result<()> {
|
||
|
|
- let mut debuginfo_elf = write::Elf::parse(debuginfo)?;
|
||
|
|
+ let mut debuginfo_elf = elf::write::Elf::parse(debuginfo)?;
|
||
|
|
let debuginfo_header = debuginfo_elf.header()?;
|
||
|
|
|
||
|
|
- if debuginfo_header.get_e_type().ne(&ET_DYN) {
|
||
|
|
+ if debuginfo_header.get_e_type().ne(&elf::ET_DYN) {
|
||
|
|
return Ok(());
|
||
|
|
}
|
||
|
|
|
||
|
|
let mut debuginfo_symbols = debuginfo_elf.symbols()?;
|
||
|
|
|
||
|
|
for mut symbol in &mut debuginfo_symbols {
|
||
|
|
- if elf_st_type(symbol.get_st_info()).ne(&STT_FILE) {
|
||
|
|
+ if elf::elf_st_type(symbol.get_st_info()).ne(&elf::STT_FILE) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
@@ -154,23 +155,23 @@ pub fn resolve_dynamic<P: AsRef<Path>>(debuginfo: P) -> Result<()> {
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
|
||
|
|
-fn _resolve_dynamic(debuginfo_symbols: &mut write::SymbolHeaderTable) -> Result<()> {
|
||
|
|
+fn _resolve_dynamic(debuginfo_symbols: &mut elf::write::SymbolHeaderTable) -> Result<()> {
|
||
|
|
for mut symbol in debuginfo_symbols {
|
||
|
|
- if elf_st_type(symbol.get_st_info()).eq(&STT_FILE) {
|
||
|
|
+ if elf::elf_st_type(symbol.get_st_info()).eq(&elf::STT_FILE) {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
- let info = symbol.get_st_info();
|
||
|
|
- if elf_st_bind(info).ne(&STB_GLOBAL) {
|
||
|
|
+ let st_info = symbol.get_st_info();
|
||
|
|
+ if elf::elf_st_bind(st_info).ne(&elf::STB_GLOBAL) {
|
||
|
|
let symbol_name = symbol.get_st_name();
|
||
|
|
trace!(
|
||
|
|
"resolve_dynamic: set {} bind {} to 1",
|
||
|
|
symbol_name.to_string_lossy(),
|
||
|
|
- elf_st_bind(info)
|
||
|
|
+ elf::elf_st_bind(st_info)
|
||
|
|
);
|
||
|
|
|
||
|
|
- let info = elf_st_type(symbol.get_st_info()) | (STB_GLOBAL << 4);
|
||
|
|
- symbol.set_st_info(info);
|
||
|
|
+ let new_st_info = elf::elf_st_type(st_info) | (elf::STB_GLOBAL << 4);
|
||
|
|
+ symbol.set_st_info(new_st_info);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
Ok(())
|
||
|
|
diff --git a/upatch-build/src/rpc/remote.rs b/upatch-build/src/rpc/remote.rs
|
||
|
|
index 9927ece..52ea6a3 100644
|
||
|
|
--- a/upatch-build/src/rpc/remote.rs
|
||
|
|
+++ b/upatch-build/src/rpc/remote.rs
|
||
|
|
@@ -54,27 +54,22 @@ impl RpcRemote {
|
||
|
|
impl RpcRemote {
|
||
|
|
fn parse_error(&self, error: Error) -> anyhow::Error {
|
||
|
|
match error {
|
||
|
|
- Error::Transport(e) => {
|
||
|
|
+ Error::Transport(err) => {
|
||
|
|
anyhow!(
|
||
|
|
"Cannot connect to upatch daemon at unix://{}, {}",
|
||
|
|
self.socket.display(),
|
||
|
|
- e.source()
|
||
|
|
+ err.source()
|
||
|
|
.map(|e| e.to_string())
|
||
|
|
.unwrap_or_else(|| "Connection timeout".to_string())
|
||
|
|
)
|
||
|
|
}
|
||
|
|
- Error::Json(e) => {
|
||
|
|
- debug!("Json parse error: {:?}", e);
|
||
|
|
+ Error::Json(err) => {
|
||
|
|
+ debug!("Json parse error: {:?}", err);
|
||
|
|
anyhow!("Failed to parse response")
|
||
|
|
}
|
||
|
|
- Error::Rpc(ref e) => match e.message == "Method not found" {
|
||
|
|
- true => {
|
||
|
|
- anyhow!("Method is unimplemented")
|
||
|
|
- }
|
||
|
|
- false => {
|
||
|
|
- anyhow!("{}", e.message)
|
||
|
|
- }
|
||
|
|
- },
|
||
|
|
+ Error::Rpc(err) => {
|
||
|
|
+ anyhow!("{}", err.message)
|
||
|
|
+ }
|
||
|
|
_ => {
|
||
|
|
debug!("{:?}", error);
|
||
|
|
anyhow!("Response is invalid")
|
||
|
|
diff --git a/upatchd/build.rs b/upatchd/build.rs
|
||
|
|
index 3809c54..6ddb941 100644
|
||
|
|
--- a/upatchd/build.rs
|
||
|
|
+++ b/upatchd/build.rs
|
||
|
|
@@ -12,26 +12,25 @@
|
||
|
|
* See the Mulan PSL v2 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
-use std::{env, process::Command};
|
||
|
|
+use std::{env, ffi::OsStr, os::unix::ffi::OsStrExt, process::Command};
|
||
|
|
|
||
|
|
fn rewrite_version() {
|
||
|
|
- const ENV_VERSION_NAME: &str = "BUILD_VERSION";
|
||
|
|
- const PKG_VERSION_NAME: &str = "CARGO_PKG_VERSION";
|
||
|
|
+ const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||
|
|
+ const ENV_VERSION: Option<&str> = option_env!("BUILD_VERSION");
|
||
|
|
|
||
|
|
- let version = env::var(ENV_VERSION_NAME).unwrap_or_else(|_| {
|
||
|
|
- let pkg_version = env::var(PKG_VERSION_NAME).expect("Failed to fetch package version");
|
||
|
|
- let git_output = Command::new("git")
|
||
|
|
- .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
- .output()
|
||
|
|
- .map(|output| String::from_utf8(output.stdout).expect("Failed to fetch git version"));
|
||
|
|
-
|
||
|
|
- match git_output {
|
||
|
|
- Ok(git_version) => format!("{}-g{}", pkg_version, git_version),
|
||
|
|
- Err(_) => pkg_version,
|
||
|
|
- }
|
||
|
|
- });
|
||
|
|
-
|
||
|
|
- println!("cargo:rustc-env={}={}", PKG_VERSION_NAME, version);
|
||
|
|
+ println!(
|
||
|
|
+ "cargo:rustc-env=CARGO_PKG_VERSION={}",
|
||
|
|
+ ENV_VERSION.map(String::from).unwrap_or_else(|| {
|
||
|
|
+ Command::new("git")
|
||
|
|
+ .args(["rev-parse", "--short", "HEAD"])
|
||
|
|
+ .output()
|
||
|
|
+ .map(|output| {
|
||
|
|
+ let git_version = OsStr::from_bytes(&output.stdout).to_string_lossy();
|
||
|
|
+ format!("{}-g{}", PKG_VERSION, git_version)
|
||
|
|
+ })
|
||
|
|
+ .unwrap_or_else(|_| PKG_VERSION.to_string())
|
||
|
|
+ })
|
||
|
|
+ );
|
||
|
|
}
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
diff --git a/upatchd/src/helper/elf_resolver.rs b/upatchd/src/helper/elf_resolver.rs
|
||
|
|
index 9b62b00..c6e5e9f 100644
|
||
|
|
--- a/upatchd/src/helper/elf_resolver.rs
|
||
|
|
+++ b/upatchd/src/helper/elf_resolver.rs
|
||
|
|
@@ -44,8 +44,8 @@ impl ElfResolver<'_> {
|
||
|
|
let lines = output.stdout.lines();
|
||
|
|
for line in lines {
|
||
|
|
let words = line.split_whitespace().collect::<Vec<_>>();
|
||
|
|
- if let Some(path) = words.get(2) {
|
||
|
|
- if let Ok(path) = fs::canonicalize(path) {
|
||
|
|
+ if let Some(lib_path) = words.get(2) {
|
||
|
|
+ if let Ok(path) = fs::canonicalize(lib_path) {
|
||
|
|
paths.push(path);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
diff --git a/upatchd/src/helper/ioctl.rs b/upatchd/src/helper/ioctl.rs
|
||
|
|
index 0efbab4..4002c3a 100644
|
||
|
|
--- a/upatchd/src/helper/ioctl.rs
|
||
|
|
+++ b/upatchd/src/helper/ioctl.rs
|
||
|
|
@@ -46,6 +46,7 @@ pub struct UpatchEnableRequest {
|
||
|
|
offset: u64,
|
||
|
|
}
|
||
|
|
|
||
|
|
+#[repr(C)]
|
||
|
|
pub struct UpatchRegisterRequest {
|
||
|
|
exec_path: [u8; PATH_MAX as usize],
|
||
|
|
jump_path: [u8; PATH_MAX as usize],
|
||
|
|
diff --git a/upatchd/src/main.rs b/upatchd/src/main.rs
|
||
|
|
index 8141679..f73be0e 100644
|
||
|
|
--- a/upatchd/src/main.rs
|
||
|
|
+++ b/upatchd/src/main.rs
|
||
|
|
@@ -117,9 +117,10 @@ impl Daemon {
|
||
|
|
|
||
|
|
// Initialize logger
|
||
|
|
let max_level = args.log_level;
|
||
|
|
- let stdout_level = match args.daemon {
|
||
|
|
- true => LevelFilter::Off,
|
||
|
|
- false => max_level,
|
||
|
|
+ let stdout_level = if args.daemon {
|
||
|
|
+ LevelFilter::Off
|
||
|
|
+ } else {
|
||
|
|
+ max_level
|
||
|
|
};
|
||
|
|
let log_spec = LogSpecification::builder().default(max_level).build();
|
||
|
|
let file_spec = FileSpec::default()
|
||
|
|
@@ -199,9 +200,10 @@ impl Daemon {
|
||
|
|
|
||
|
|
fs::set_permissions(
|
||
|
|
&socket_file,
|
||
|
|
- match socket_owner.as_raw() == socket_group.as_raw() {
|
||
|
|
- true => Permissions::from_mode(SOCKET_FILE_PERM_STRICT),
|
||
|
|
- false => Permissions::from_mode(SOCKET_FILE_PERM),
|
||
|
|
+ if socket_owner.as_raw() == socket_group.as_raw() {
|
||
|
|
+ Permissions::from_mode(SOCKET_FILE_PERM_STRICT)
|
||
|
|
+ } else {
|
||
|
|
+ Permissions::from_mode(SOCKET_FILE_PERM)
|
||
|
|
},
|
||
|
|
)?;
|
||
|
|
|
||
|
|
--
|
||
|
|
2.34.1
|
||
|
|
|