mirror of
https://github.com/hanzoai/dev.git
synced 2026-10-25 03:32:32 +00:00
fix(core): gate cgroup helpers on Linux
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -172,24 +173,3 @@ pub(crate) fn best_effort_cleanup_exec_cgroup(pid: u32) {
|
||||
// Only remove the per-pid directory. The parent container stays.
|
||||
let _ = std::fs::remove_dir(&dir);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) fn default_exec_memory_max_bytes() -> Option<u64> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) fn best_effort_attach_self_to_exec_cgroup(_pid: u32, _memory_max_bytes: u64) {}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) fn exec_cgroup_oom_killed(_pid: u32) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) fn exec_cgroup_memory_max_bytes(_pid: u32) -> Option<u64> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) fn best_effort_cleanup_exec_cgroup(_pid: u32) {}
|
||||
|
||||
+21
-14
@@ -564,24 +564,31 @@ async fn consume_truncated_output(
|
||||
combined_handle.await.map_err(CodexErr::from)?
|
||||
};
|
||||
|
||||
let mut oom_killed = false;
|
||||
let mut cgroup_memory_max_bytes: Option<u64> = None;
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if !timed_out {
|
||||
if let Some(pid) = pid {
|
||||
if matches!(exit_status.signal(), Some(SIGKILL_CODE))
|
||||
&& crate::cgroup::exec_cgroup_oom_killed(pid).unwrap_or(false)
|
||||
{
|
||||
oom_killed = true;
|
||||
cgroup_memory_max_bytes = crate::cgroup::exec_cgroup_memory_max_bytes(pid);
|
||||
let (oom_killed, cgroup_memory_max_bytes) = {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let mut oom_killed = false;
|
||||
let mut cgroup_memory_max_bytes: Option<u64> = None;
|
||||
if !timed_out {
|
||||
if let Some(pid) = pid {
|
||||
if matches!(exit_status.signal(), Some(SIGKILL_CODE))
|
||||
&& crate::cgroup::exec_cgroup_oom_killed(pid).unwrap_or(false)
|
||||
{
|
||||
oom_killed = true;
|
||||
cgroup_memory_max_bytes = crate::cgroup::exec_cgroup_memory_max_bytes(pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(pid) = pid {
|
||||
crate::cgroup::best_effort_cleanup_exec_cgroup(pid);
|
||||
}
|
||||
(oom_killed, cgroup_memory_max_bytes)
|
||||
}
|
||||
if let Some(pid) = pid {
|
||||
crate::cgroup::best_effort_cleanup_exec_cgroup(pid);
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
(false, None)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(RawExecToolCallOutput {
|
||||
exit_status,
|
||||
|
||||
@@ -135,8 +135,6 @@ pub(crate) async fn spawn_child_async(
|
||||
StdioPolicy::RedirectForShellTool => crate::cgroup::default_exec_memory_max_bytes(),
|
||||
StdioPolicy::Inherit => None,
|
||||
};
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
let exec_memory_max_bytes: Option<u64> = None;
|
||||
cmd.pre_exec(move || {
|
||||
// Start a new process group
|
||||
let _ = libc::setpgid(0, 0);
|
||||
|
||||
Reference in New Issue
Block a user