Skip to content

Commit

Permalink
Add horrific cfg blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Nov 29, 2024
1 parent 6c5b0e2 commit 04f78bc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3853,7 +3853,9 @@ receives a fatal signal, `just` halts execution.
#### `SIGINFO`

`SIGINFO` is sent to all processes in the foreground process group when the
user types `ctrl-t`.
user types `ctrl-t` on
[BSD](https://en.wikipedia.org/wiki/Berkeley_Software_Distribution)-derived
operating systems, including MacOS, but not Linux.

`just` responds by printing a list of all child process IDs and
commands<sup>master</sup>.
Expand Down
40 changes: 40 additions & 0 deletions src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ use super::*;
#[repr(i32)]
pub(crate) enum Signal {
Hangup = libc::SIGHUP,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))]
Info = libc::SIGINFO,
Interrupt = libc::SIGINT,
Quit = libc::SIGQUIT,
Expand All @@ -13,6 +21,14 @@ pub(crate) enum Signal {
impl Signal {
pub(crate) const ALL: [Signal; 5] = [
Signal::Hangup,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))]
Signal::Info,
Signal::Interrupt,
Signal::Quit,
Expand All @@ -31,6 +47,14 @@ impl Display for Signal {
"{}",
match self {
Signal::Hangup => "SIGHUP",
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))]
Signal::Info => "SIGINFO",
Signal::Interrupt => "SIGINT",
Signal::Quit => "SIGQUIT",
Expand All @@ -44,6 +68,14 @@ impl From<Signal> for nix::sys::signal::Signal {
fn from(signal: Signal) -> Self {
match signal {
Signal::Hangup => Self::SIGHUP,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))]
Signal::Info => Self::SIGINFO,
Signal::Interrupt => Self::SIGINT,
Signal::Quit => Self::SIGQUIT,
Expand All @@ -58,6 +90,14 @@ impl TryFrom<u8> for Signal {
fn try_from(n: u8) -> Result<Signal, Self::Error> {
match n.into() {
libc::SIGHUP => Ok(Signal::Hangup),
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))]
libc::SIGINFO => Ok(Signal::Info),
libc::SIGINT => Ok(Signal::Interrupt),
libc::SIGQUIT => Ok(Signal::Quit),
Expand Down
16 changes: 16 additions & 0 deletions src/signal_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ impl SignalHandler {
process::exit(128 + signal.number());
}

#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))]
if signal != Signal::Info && self.caught.is_none() {
self.caught = Some(signal);
}
Expand All @@ -60,6 +68,14 @@ impl SignalHandler {
nix::sys::signal::kill(child, Some(Signal::Terminate.into())).ok();
}
}
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))]
Signal::Info => {
// todo: print pid
if self.children.is_empty() {
Expand Down

0 comments on commit 04f78bc

Please sign in to comment.