fix: remove meaningless input from other_error macro
Signed-off-by: Lei Liu <liulei.pt@bytedance.com>
This commit is contained in:
parent
a6b4286542
commit
c22dba6201
|
|
@ -93,7 +93,7 @@ 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)?;
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ pub async fn register_memory_event(
|
|||
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];
|
||||
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
@ -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) => {
|
||||
|
|
@ -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"))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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"))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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"))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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"))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"))]
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue