| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 2 | |
| 3 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::interfacerust-analyzer cargo sudo-rs 0.2.14 system/interface/::ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#; |
| 4 | |
| 5 | use superrust-analyzer cargo sudo-rs 0.2.14 system/signal/::SignalNumberrust-analyzer cargo sudo-rs 0.2.14 system/signal/SignalNumber#; |
| 6 | |
| 7 | /// Information related to the arrival of a signal. |
| 8 | #[repr(transparent)] |
| 9 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) struct SignalInforust-analyzer cargo sudo-rs 0.2.14 system/signal/info/SignalInfo# { |
| 10 | inforust-analyzer cargo sudo-rs 0.2.14 system/signal/info/SignalInfo#info.: libcrust-analyzer cargo libc 0.2.186 crate/::siginfo_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/siginfo_t#, |
| 11 | } |
| 12 | |
| 13 | impl SignalInforust-analyzer cargo sudo-rs 0.2.14 system/signal/info/SignalInfo# { |
| 14 | pub(superrust-analyzer cargo sudo-rs 0.2.14 system/signal/) const SIZErust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo]SIZE.: usize = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<Selfrust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo]>(); |
| 15 | |
| 16 | /// Returns whether the signal was sent by the user or not. |
| 17 | fn is_user_signaledrust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo]is_user_signaled().(&self) -> bool { |
| 18 | // This matches the definition of the SI_FROMUSER macro. |
| 19 | self.inforust-analyzer cargo sudo-rs 0.2.14 system/signal/info/SignalInfo#info..si_coderust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/siginfo_t#si_code. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().0 |
| 20 | } |
| 21 | |
| 22 | /// Gets the PID that sent the signal. |
| 23 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn signaler_pidrust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo]signaler_pid().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#> { |
| 24 | if self.is_user_signaledrust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo]is_user_signaled().() { |
| 25 | // SAFETY: si_pid is always initialized if the signal is user signaled. |
| 26 | let id = unsafe { self.inforust-analyzer cargo sudo-rs 0.2.14 system/signal/info/SignalInfo#info..si_pidrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/impl#[siginfo_t]si_pid().() }; |
| 27 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(id)) |
| 28 | } else { |
| 29 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /// Gets the signal number. |
| 34 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn signalrust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo]signal().(&self) -> SignalNumberrust-analyzer cargo sudo-rs 0.2.14 system/signal/SignalNumber# { |
| 35 | self.inforust-analyzer cargo sudo-rs 0.2.14 system/signal/info/SignalInfo#info..si_signorust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/siginfo_t#si_signo. |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for SignalInforust-analyzer cargo sudo-rs 0.2.14 system/signal/info/SignalInfo# { |
| 40 | fn fmtrust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 41 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 42 | f, |
| 43 | "{} {} from ", |
| 44 | if self.is_user_signaledrust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo]is_user_signaled().() { |
| 45 | " user signaled" |
| 46 | } else { |
| 47 | "" |
| 48 | }, |
| 49 | self.signalrust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo]signal().(), |
| 50 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 51 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pid) = self.signaler_pidrust-analyzer cargo sudo-rs 0.2.14 system/signal/info/impl#[SignalInfo]signaler_pid().() { |
| 52 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{pid}") |
| 53 | } else { |
| 54 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "<none>") |
| 55 | } |
| 56 | } |
| 57 | } |