1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Subprocess handling is platform specific code.
//!
//! The submodules of this module represent the different implementations for
//! each supported platform.
//! Depending on the target, the respective platform is read and loaded into this scope.

use crate::network::message::Signal as InternalSignal;

// Unix specific process handling
// Shared between Linux and Apple
#[cfg(unix)]
mod unix;
#[cfg(unix)]
pub use self::unix::*;
#[cfg(unix)]
use command_group::Signal;

// Linux specific process support
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use self::linux::process_exists;

// Apple specific process support
#[cfg(target_vendor = "apple")]
mod apple;
#[cfg(target_vendor = "apple")]
pub use self::apple::process_exists;

// Windows specific process handling
#[cfg(any(target_os = "windows"))]
mod windows;
#[cfg(target_os = "windows")]
pub use self::windows::*;

/// Pueue directly interacts with processes.
/// Since these interactions can vary depending on the current platform, this enum is introduced.
/// The intend is to keep any platform specific code out of the top level code.
/// Even if that implicates adding some layers of abstraction.
#[derive(Debug)]
pub enum ProcessAction {
    Pause,
    Resume,
}

impl From<&ProcessAction> for Signal {
    fn from(action: &ProcessAction) -> Self {
        match action {
            ProcessAction::Pause => Signal::SIGSTOP,
            ProcessAction::Resume => Signal::SIGCONT,
        }
    }
}

impl From<InternalSignal> for Signal {
    fn from(signal: InternalSignal) -> Self {
        match signal {
            InternalSignal::SigKill => Signal::SIGKILL,
            InternalSignal::SigInt => Signal::SIGINT,
            InternalSignal::SigTerm => Signal::SIGTERM,
            InternalSignal::SigCont => Signal::SIGCONT,
            InternalSignal::SigStop => Signal::SIGSTOP,
        }
    }
}