Skip to main content

wasmer_wasix/syscalls/wasix/
proc_signal.rs

1use super::*;
2use crate::syscalls::*;
3
4/// ### `proc_signal()`
5/// Sends a signal to a child process
6///
7/// ## Parameters
8///
9/// * `pid` - Handle of the child process to wait on
10/// * `sig` - Signal to send the child process
11#[instrument(level = "trace", skip_all, fields(%pid, ?sig), ret)]
12pub fn proc_signal(
13    mut ctx: FunctionEnvMut<'_, WasiEnv>,
14    pid: Pid,
15    sig: Signal,
16) -> Result<Errno, WasiError> {
17    // A non-positive PID addresses a process group or every process, as in
18    // kill(2). WASIX has no process groups, and the caller's own group always
19    // exists, so these stay a no-op rather than reporting ESRCH.
20    let result = if (pid as i32) <= 0 {
21        Errno::Success
22    } else if let Some(process) = ctx.data().control_plane.get_process(pid.into()) {
23        process.signal_process(sig);
24        Errno::Success
25    } else {
26        Errno::Srch
27    };
28
29    WasiEnv::do_pending_operations(&mut ctx)?;
30
31    Ok(result)
32}