Skip to content

Commit

Permalink
fix: remove meaningless input from other_error macro
Browse files Browse the repository at this point in the history
Signed-off-by: Lei Liu <[email protected]>
  • Loading branch information
zhaodiaoer authored and mxpv committed Oct 30, 2024
1 parent a6b4286 commit c22dba6
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions crates/runc-shim/src/cgroup_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ pub async fn register_memory_event(
let path = cg_dir.join(event_name);
let event_file = fs::File::open(path.clone())
.await
.map_err(other_error!(e, "Error get path:"))?;
.map_err(other_error!("Error get path:"))?;

let eventfd = EventFd::from_value_and_flags(0, EfdFlags::EFD_CLOEXEC)?;

let event_control_path = cg_dir.join("cgroup.event_control");
let data = format!("{} {}", eventfd.as_raw_fd(), event_file.as_raw_fd());
fs::write(&event_control_path, data.clone())
.await
.map_err(other_error!(e, "Error write eventfd:"))?;
.map_err(other_error!("Error write eventfd:"))?;

let mut buf = [0u8; 8];

Expand Down
2 changes: 1 addition & 1 deletion crates/runc-shim/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub fn create_runc(
}
gopts
.build()
.map_err(other_error!(e, "unable to create runc instance"))
.map_err(other_error!("unable to create runc instance"))
}

#[derive(Default)]
Expand Down
2 changes: 1 addition & 1 deletion crates/runc-shim/src/runc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl ProcessLifecycle<InitProcess> for RuncInitLifecycle {
.runtime
.ps(&p.id)
.await
.map_err(other_error!(e, "failed to execute runc ps"))?;
.map_err(other_error!("failed to execute runc ps"))?;
Ok(pids
.iter()
.map(|&x| ProcessInfo {
Expand Down
2 changes: 1 addition & 1 deletion crates/runc-shim/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async fn monitor_oom(id: &String, pid: u32, tx: EventSender) -> Result<()> {
"memory.oom_control",
)
.await
.map_err(other_error!(e, "register_memory_event failed:"))?;
.map_err(other_error!("register_memory_event failed:"))?;

run_oom_monitor(rx, id.to_string(), tx);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/shim/src/asynchronous/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Monitor {
subject: subject.clone(),
exit_code,
})
.map_err(other_error!(e, "failed to send exit code"));
.map_err(other_error!("failed to send exit code"));
results.push(res);
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/shim/src/asynchronous/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where
{
spawn_blocking(f)
.await
.map_err(other_error!(e, "failed to spawn blocking task"))?
.map_err(other_error!("failed to spawn blocking task"))?
}

pub async fn read_file_to_str(path: impl AsRef<Path>) -> Result<String> {
Expand Down Expand Up @@ -96,14 +96,14 @@ pub async fn read_pid_from_file(pid_path: &Path) -> Result<i32> {
pub async fn read_spec(bundle: impl AsRef<Path>) -> Result<Spec> {
let path = bundle.as_ref().join(CONFIG_FILE_NAME);
let content = read_file_to_str(&path).await?;
serde_json::from_str::<Spec>(content.as_str()).map_err(other_error!(e, "read spec"))
serde_json::from_str::<Spec>(content.as_str()).map_err(other_error!("read spec"))
}

pub async fn read_options(bundle: impl AsRef<Path>) -> Result<Options> {
let path = bundle.as_ref().join(OPTIONS_FILE_NAME);
let opts_str = read_file_to_str(path).await?;
let opts =
serde_json::from_str::<JsonOptions>(&opts_str).map_err(other_error!(e, "read options"))?;
serde_json::from_str::<JsonOptions>(&opts_str).map_err(other_error!("read options"))?;
Ok(opts.into())
}

Expand Down
34 changes: 17 additions & 17 deletions crates/shim/src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn add_task_to_cgroup(path: &str, pid: u32) -> Result<()> {

Cgroup::load(h, path)
.add_task_by_tgid(CgroupPid::from(pid as u64))
.map_err(other_error!(e, "add task to cgroup"))
.map_err(other_error!("add task to cgroup"))
}

/// Sets the OOM score for the process to the parents OOM score + 1
Expand All @@ -92,7 +92,7 @@ fn read_process_oom_score(pid: u32) -> Result<i64> {
let score = content
.trim()
.parse::<i64>()
.map_err(other_error!(e, "parse oom score"))?;
.map_err(other_error!("parse oom score"))?;
Ok(score)
}

Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn collect_metrics(pid: u32) -> Result<Metrics> {
pid_stats.set_current(
pid_ctr
.get_pid_current()
.map_err(other_error!(e, "get current pid"))?,
.map_err(other_error!("get current pid"))?,
);
pid_stats.set_limit(
pid_ctr
Expand All @@ -174,7 +174,7 @@ pub fn collect_metrics(pid: u32) -> Result<Metrics> {
cgroups_rs::MaxValue::Max => 0,
cgroups_rs::MaxValue::Value(val) => val as u64,
})
.map_err(other_error!(e, "get pid limit"))?,
.map_err(other_error!("get pid limit"))?,
);
metrics.set_pids(pid_stats)
}
Expand All @@ -193,8 +193,8 @@ fn get_cgroup(pid: u32) -> Result<Cgroup> {
Cgroup::load(hierarchies, path)
} else {
// get container main process cgroup
let path = get_cgroups_relative_paths_by_pid(pid)
.map_err(other_error!(e, "get process cgroup"))?;
let path =
get_cgroups_relative_paths_by_pid(pid).map_err(other_error!("get process cgroup"))?;
Cgroup::load_with_relative_paths(hierarchies::auto(), Path::new("."), path)
};
Ok(cgroup)
Expand Down Expand Up @@ -243,7 +243,7 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> {
if let Some(pids) = resources.pids() {
pid_ctr
.set_pid_max(MaxValue::Value(pids.limit()))
.map_err(other_error!(e, "set pid max"))?;
.map_err(other_error!("set pid max"))?;
}
}
Subsystem::Mem(mem_ctr) => {
Expand All @@ -257,24 +257,24 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> {
if current < swap {
mem_ctr
.set_memswap_limit(swap)
.map_err(other_error!(e, "set memsw limit"))?;
.map_err(other_error!("set memsw limit"))?;
mem_ctr
.set_limit(limit)
.map_err(other_error!(e, "set mem limit"))?;
.map_err(other_error!("set mem limit"))?;
}
}
// set memory limit in bytes
if let Some(limit) = memory.limit() {
mem_ctr
.set_limit(limit)
.map_err(other_error!(e, "set mem limit"))?;
.map_err(other_error!("set mem limit"))?;
}

// set memory swap limit in bytes
if let Some(swap) = memory.swap() {
mem_ctr
.set_memswap_limit(swap)
.map_err(other_error!(e, "set memsw limit"))?;
.map_err(other_error!("set memsw limit"))?;
}
}
}
Expand All @@ -284,14 +284,14 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> {
if let Some(cpus) = cpu.cpus() {
cpuset_ctr
.set_cpus(cpus)
.map_err(other_error!(e, "set CPU sets"))?;
.map_err(other_error!("set CPU sets"))?;
}

// set list of memory nodes in the cpuset
if let Some(mems) = cpu.mems() {
cpuset_ctr
.set_mems(mems)
.map_err(other_error!(e, "set CPU memes"))?;
.map_err(other_error!("set CPU memes"))?;
}
}
}
Expand All @@ -301,21 +301,21 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> {
if let Some(shares) = cpu.shares() {
cpu_ctr
.set_shares(shares)
.map_err(other_error!(e, "set CPU share"))?;
.map_err(other_error!("set CPU share"))?;
}

// set CPU hardcap limit
if let Some(quota) = cpu.quota() {
cpu_ctr
.set_cfs_quota(quota)
.map_err(other_error!(e, "set CPU quota"))?;
.map_err(other_error!("set CPU quota"))?;
}

// set CPU hardcap period
if let Some(period) = cpu.period() {
cpu_ctr
.set_cfs_period(period)
.map_err(other_error!(e, "set CPU period"))?;
.map_err(other_error!("set CPU period"))?;
}
}
}
Expand All @@ -325,7 +325,7 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> {
for limit in hp_limits {
ht_ctr
.set_limit_in_bytes(limit.page_size().as_str(), limit.limit() as u64)
.map_err(other_error!(e, "set huge page limit"))?;
.map_err(other_error!("set huge page limit"))?;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/shim/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ macro_rules! other {

#[macro_export]
macro_rules! other_error {
($e:ident, $s:expr) => {
|$e| Error::Other($s.to_string() + &": ".to_string() + &$e.to_string())
($s:expr) => {
|e| Error::Other(format!("{}: {}", $s, e))
};
}
2 changes: 1 addition & 1 deletion crates/shim/src/reap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::error::Result;
/// on the process to discover its termination status.
pub fn set_subreaper() -> Result<()> {
use crate::error::Error;
prctl::set_child_subreaper(true).map_err(other_error!(code, "linux prctl returned"))
prctl::set_child_subreaper(true).map_err(other_error!("linux prctl returned"))
}

#[cfg(not(target_os = "linux"))]
Expand Down
2 changes: 1 addition & 1 deletion crates/shim/src/synchronous/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn write_address(address: &str) -> crate::Result<()> {

pub fn read_spec_from_file(bundle: &str) -> crate::Result<Spec> {
let path = Path::new(bundle).join("config.json");
Spec::load(path).map_err(other_error!(e, "read spec file"))
Spec::load(path).map_err(other_error!("read spec file"))
}

#[cfg(unix)]
Expand Down

0 comments on commit c22dba6

Please sign in to comment.