Skip to content

Commit

Permalink
feat(builtins): add builtin Kill
Browse files Browse the repository at this point in the history
  • Loading branch information
sivizius committed Jul 3, 2024
1 parent b56d18c commit 497afa1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
40 changes: 40 additions & 0 deletions src/builtins/kill.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Allow `sys_kill`.
use {crate::RuleSet, syscalls::Sysno};

/// Allow the syscall `kill` to send signals to other processes.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, PartialOrd)]
#[must_use]
pub struct Kill;

impl RuleSet for Kill {
fn simple_rules(&self) -> Vec<Sysno> {
Vec::from([Sysno::kill])
}

fn name(&self) -> &'static str {
"Kill"
}
}

#[cfg(test)]
mod tests {
use {super::Kill, crate::RuleSet as _, syscalls::Sysno};

#[test]
fn name() {
assert_eq!(Kill.name(), "Kill");
}

#[test]
fn simple_rules() {
let rules = Kill.simple_rules();
assert_eq!(rules.len(), 1);
assert!(rules.contains(&Sysno::kill));
}

#[test]
fn conditional_rules() {
assert!(Kill.conditional_rules().is_empty());
}
}
31 changes: 13 additions & 18 deletions src/builtins/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
//! Built-in [`RuleSet`](crate::RuleSet)s
pub mod basic;
pub mod danger_zone;
pub mod kill;
pub mod network;
pub mod pipes;
pub mod systemio;
pub mod time;

pub use {
basic::BasicCapabilities, kill::Kill, network::Networking, systemio::SystemIO, time::Time,
};

/// A struct whose purpose is to make you read the documentation for the function you're calling.
/// If you're reading this, go read the documentation for the function that is returning this
/// object.
Expand All @@ -16,23 +28,6 @@ impl<T> YesReally<T> {

/// Make a [`YesReally`].
pub fn new(inner: T) -> YesReally<T> {
YesReally {
inner,
}
YesReally { inner }
}
}

pub mod basic;
pub use basic::BasicCapabilities;

pub mod systemio;
pub use systemio::SystemIO;

pub mod network;
pub use network::Networking;

pub mod time;
pub use time::Time;

pub mod danger_zone;
pub mod pipes;

0 comments on commit 497afa1

Please sign in to comment.