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
66
67
68
69
70
71
72
73
74
75
76
//! [`EventSignal`]
use endpoint_sec_sys::es_event_signal_t;
use crate::Process;
/// Send a signal to a process event.
///
/// Signals may be sent on behalf of another process or directly. Notably
/// launchd often sends signals on behalf of another process for service start/
/// stop operations. If this is the case an instigator will be provided. The
/// relationship between each process is illustrated below:
///
/// Delegated Signal:
///
/// ```
/// Instigator Process -> IPC to Sender Process (launchd) -> Target Process
/// ```
///
/// Direct Signal:
///
/// ```
/// Sender Process -> Target Process
/// ```
///
/// Clients may wish to block delegated signals from launchd for non-authorized
/// instigators, while still allowing direct signals initiated by launchd for
/// shutdown/reboot/restart.
#[doc(alias = "es_event_signal_t")]
pub struct EventSignal<'a> {
/// The raw reference.
pub(crate) raw: &'a es_event_signal_t,
/// The version of the message.
pub(crate) version: u32,
}
impl<'a> EventSignal<'a> {
/// The signal number to be delivered.
#[inline(always)]
pub fn sig(&self) -> i32 {
self.raw.sig
}
/// The process that will receive the signal.
#[inline(always)]
pub fn target(&self) -> Process<'a> {
// Safety: 'a tied to self, object obtained through ES
Process::new(unsafe { self.raw.target() }, self.version)
}
/// Process information for the instigator.
///
/// Only available for delegated signals.
///
/// Note: Only available only if message version >= 9.
#[cfg(feature = "macos_15_4_0")]
#[inline(always)]
pub fn instigator(&self) -> Option<Process<'a>> {
if self.version >= 9 {
// Safety: 'a tied to self, object obtained through ES
let process = unsafe { self.raw.instigator()? };
Some(Process::new(process, self.version))
} else {
None
}
}
}
// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
unsafe impl Send for EventSignal<'_> {}
// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
unsafe impl Sync for EventSignal<'_> {}
impl_debug_eq_hash_with_functions!(EventSignal<'a> with version; sig, target, #[cfg(feature = "macos_15_4_0")] instigator);