use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Containment {
CgroupV2,
JobObject,
ProcessGroup,
Session,
FdMarker,
TreeWalk,
Delegated,
None,
}
impl Containment {
pub fn can_teardown(&self) -> bool {
match self {
Containment::CgroupV2
| Containment::JobObject
| Containment::ProcessGroup
| Containment::Session
| Containment::FdMarker
| Containment::TreeWalk => true,
Containment::None | Containment::Delegated => false,
}
}
pub fn can_observe_drain(&self) -> bool {
matches!(
self,
Containment::CgroupV2 | Containment::JobObject | Containment::FdMarker
)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TreeDrain {
AllMembersExited,
AllMarkersClosed,
MembersRemain,
}
impl TreeDrain {
pub(crate) fn permits_skipping_sweep(&self) -> bool {
match self {
TreeDrain::AllMembersExited => true,
TreeDrain::AllMarkersClosed | TreeDrain::MembersRemain => false,
}
}
}
impl fmt::Display for Containment {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Containment::CgroupV2 => "cgroup v2",
Containment::JobObject => "job object",
Containment::ProcessGroup => "process group",
Containment::Session => "session",
Containment::FdMarker => "inherited-fd marker",
Containment::TreeWalk => "process-tree walk",
Containment::Delegated => "delegated",
Containment::None => "none",
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ContainMode {
Strongest,
TreeWalk,
Session,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Nesting {
#[default]
Mark,
Opaque,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct ContainRequest {
pub mode: Option<ContainMode>,
pub nesting: Nesting,
}
impl Default for ContainRequest {
fn default() -> ContainRequest {
ContainRequest {
mode: None,
nesting: Nesting::Mark,
}
}
}
pub(crate) const NESTED_ENV: &str = "__COSCA_GROUP_ROOT";
#[cfg(unix)]
#[path = "containment/unix.rs"]
pub(crate) mod unix;
#[path = "containment/cgroup.rs"]
pub(crate) mod cgroup;
#[cfg(windows)]
#[path = "containment/windows.rs"]
pub(crate) mod windows;
#[cfg(windows)]
#[path = "containment/job.rs"]
pub(crate) mod job;
#[cfg(windows)]
pub use job::Job;
#[path = "containment/enumerate.rs"]
pub(crate) mod enumerate;
#[cfg(target_os = "macos")]
#[path = "containment/fdmarker.rs"]
pub(crate) mod fdmarker;
#[cfg(any(target_os = "macos", test))]
#[path = "containment/sweep_passes.rs"]
pub(crate) mod sweep_passes;
#[path = "containment/treewalk.rs"]
pub(crate) mod treewalk;
#[path = "containment/dispatch.rs"]
pub(crate) mod dispatch;
#[path = "containment/mechanism.rs"]
pub(crate) mod mechanism;
#[path = "containment/drain_edge.rs"]
pub(crate) mod drain_edge;
#[cfg(test)]
#[path = "containment/fake.rs"]
pub(crate) mod fake;
#[path = "containment/tree.rs"]
mod tree;
#[path = "containment/tree_kill.rs"]
pub(crate) mod tree_kill;
#[path = "containment/root.rs"]
mod root;
#[path = "containment/skip.rs"]
mod skip;
#[cfg(target_os = "linux")]
pub(crate) use dispatch::ChildHandle;
#[cfg(unix)]
pub(crate) use dispatch::DropView;
#[allow(
unused_imports,
reason = "not every re-exported name here is consumed on every target/feature combination; re-exporting uniformly beats per-item cfg_attr gating"
)]
pub(crate) use dispatch::{attach, prepare, Attachment, Prepared, RootIdentity, TreeKilled};
#[allow(
unused_imports,
reason = "a mechanism is named outside containment/ only by tests and the macOS late spawn"
)]
pub(crate) use mechanism::{Contains, Mechanism};
#[cfg(all(test, unix))]
pub(crate) use root::Refusal;
pub(crate) use root::Root;
#[cfg(unix)]
pub(crate) use root::Seen;
#[cfg(unix)]
pub(crate) use root::{check_number, NotItsGroup};
pub(crate) use skip::{Skip, TerminateOutcome};
#[cfg(unix)]
pub(crate) use skip::{SkipCall, Why};
pub(crate) use tree::Tree;
#[allow(
unused_imports,
reason = "a wait is named outside containment/ only by the callers that wait; the rest send alone"
)]
pub(crate) use tree_kill::{KillWait, TreeKill};
#[cfg(target_os = "macos")]
#[path = "containment/marker_eof.rs"]
pub(crate) mod marker_eof;
#[cfg(test)]
#[path = "containment_tests.rs"]
mod containment_tests;