diff --git a/cliff.toml b/cliff.toml index 4dba12f..c54ec0b 100644 --- a/cliff.toml +++ b/cliff.toml @@ -56,6 +56,7 @@ link_parsers = [ ] commit_parsers = [ + { message = "^api", group = "API change" }, { message = "^feat", group = "Feature" }, { message = "^fix", group = "Bugfix" }, { message = "^tweak", group = "Tweak" }, diff --git a/src/std/core.rs b/src/std/core.rs index 02206c2..917d4de 100644 --- a/src/std/core.rs +++ b/src/std/core.rs @@ -120,7 +120,7 @@ pub trait StdChildWrapper: std::fmt::Debug + Send + Sync { fn start_kill(&mut self) -> Result<()> { #[cfg(unix)] { - self.signal(Signal::SIGKILL) + self.signal(Signal::SIGKILL as _) } #[cfg(not(unix))] @@ -195,10 +195,10 @@ pub trait StdChildWrapper: std::fmt::Debug + Send + Sync { /// was introduced by command-group to abstract over the signal behaviour between process groups /// and unwrapped processes. #[cfg(unix)] - fn signal(&self, sig: Signal) -> Result<()> { + fn signal(&self, sig: i32) -> Result<()> { kill( Pid::from_raw(i32::try_from(self.id()).map_err(std::io::Error::other)?), - sig, + Signal::try_from(sig)?, ) .map_err(std::io::Error::from) } diff --git a/src/std/process_group.rs b/src/std/process_group.rs index df57b7d..1d0656a 100644 --- a/src/std/process_group.rs +++ b/src/std/process_group.rs @@ -45,8 +45,10 @@ impl ProcessGroup { } /// Create a process group wrapper attaching the command to an existing process group ID. - pub fn attach_to(leader: Pid) -> Self { - Self { leader } + pub fn attach_to(leader: u32) -> Self { + Self { + leader: Pid::from_raw(leader as _), + } } } @@ -71,8 +73,8 @@ impl ProcessGroupChild { /// Get the process group ID of this child process. /// /// See: [`man 'setpgid(2)'`](https://www.man7.org/linux/man-pages/man2/setpgid.2.html) - pub fn pgid(&self) -> Pid { - self.pgid + pub fn pgid(&self) -> u32 { + self.pgid.as_raw() as _ } } @@ -215,7 +217,7 @@ impl StdChildWrapper for ProcessGroupChild { } } - fn signal(&self, sig: Signal) -> Result<()> { - self.signal_imp(sig) + fn signal(&self, sig: i32) -> Result<()> { + self.signal_imp(Signal::try_from(sig)?) } } diff --git a/src/tokio/core.rs b/src/tokio/core.rs index 17efc98..8ed3311 100644 --- a/src/tokio/core.rs +++ b/src/tokio/core.rs @@ -192,11 +192,11 @@ pub trait TokioChildWrapper: std::fmt::Debug + Send + Sync { /// was introduced by command-group to abstract over the signal behaviour between process groups /// and unwrapped processes. #[cfg(unix)] - fn signal(&self, sig: Signal) -> Result<()> { + fn signal(&self, sig: i32) -> Result<()> { if let Some(id) = self.id() { kill( Pid::from_raw(i32::try_from(id).map_err(std::io::Error::other)?), - sig, + Signal::try_from(sig)?, ) .map_err(std::io::Error::from) } else { diff --git a/src/tokio/process_group.rs b/src/tokio/process_group.rs index ac451e2..7a8f93f 100644 --- a/src/tokio/process_group.rs +++ b/src/tokio/process_group.rs @@ -78,8 +78,8 @@ impl ProcessGroupChild { /// Get the process group ID of this child process. /// /// See: [`man 'setpgid(2)'`](https://www.man7.org/linux/man-pages/man2/setpgid.2.html) - pub fn pgid(&self) -> Pid { - self.pgid + pub fn pgid(&self) -> u32 { + self.pgid.as_raw() as _ } } @@ -242,7 +242,7 @@ impl TokioChildWrapper for ProcessGroupChild { } } - fn signal(&self, sig: Signal) -> Result<()> { - self.signal_imp(sig) + fn signal(&self, sig: i32) -> Result<()> { + self.signal_imp(Signal::try_from(sig)?) } } diff --git a/tests/std_unix/signals.rs b/tests/std_unix/signals.rs index ecdda09..71196de 100644 --- a/tests/std_unix/signals.rs +++ b/tests/std_unix/signals.rs @@ -7,11 +7,11 @@ fn nowrap() -> Result<()> { }) .spawn()?; - child.signal(Signal::SIGCONT)?; + child.signal(Signal::SIGCONT as _)?; sleep(DIE_TIME); assert!(child.try_wait()?.is_none(), "not exited with sigcont"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME); assert!(child.try_wait()?.is_some(), "exited with sigterm"); @@ -26,11 +26,11 @@ fn process_group() -> Result<()> { .wrap(ProcessGroup::leader()) .spawn()?; - child.signal(Signal::SIGCONT)?; + child.signal(Signal::SIGCONT as _)?; sleep(DIE_TIME); assert!(child.try_wait()?.is_none(), "not exited with sigcont"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME); assert!(child.try_wait()?.is_some(), "exited with sigterm"); @@ -45,11 +45,11 @@ fn process_session() -> Result<()> { .wrap(ProcessSession) .spawn()?; - child.signal(Signal::SIGCONT)?; + child.signal(Signal::SIGCONT as _)?; sleep(DIE_TIME); assert!(child.try_wait()?.is_none(), "not exited with sigcont"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME); assert!(child.try_wait()?.is_some(), "exited with sigterm"); diff --git a/tests/std_unix/try_wait_twice_after_sigterm.rs b/tests/std_unix/try_wait_twice_after_sigterm.rs index 3670ec7..00f0a8e 100644 --- a/tests/std_unix/try_wait_twice_after_sigterm.rs +++ b/tests/std_unix/try_wait_twice_after_sigterm.rs @@ -8,7 +8,7 @@ fn nowrap() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME); assert!(child.try_wait()?.is_some(), "try_wait() one"); @@ -27,7 +27,7 @@ fn process_group() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME); assert!(child.try_wait()?.is_some(), "try_wait() one"); @@ -46,7 +46,7 @@ fn process_session() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME); assert!(child.try_wait()?.is_some(), "try_wait() one"); diff --git a/tests/std_unix/wait_twice_after_sigterm.rs b/tests/std_unix/wait_twice_after_sigterm.rs index 03ec783..7cb5165 100644 --- a/tests/std_unix/wait_twice_after_sigterm.rs +++ b/tests/std_unix/wait_twice_after_sigterm.rs @@ -8,7 +8,7 @@ fn nowrap() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; let status = (child.wait())?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() one"); @@ -28,7 +28,7 @@ fn process_group() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; let status = (child.wait())?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() one"); @@ -48,7 +48,7 @@ fn process_session() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; let status = (child.wait())?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() one"); diff --git a/tests/tokio_unix/signals.rs b/tests/tokio_unix/signals.rs index a5a49ba..4de5e71 100644 --- a/tests/tokio_unix/signals.rs +++ b/tests/tokio_unix/signals.rs @@ -7,11 +7,11 @@ async fn nowrap() -> Result<()> { }) .spawn()?; - child.signal(Signal::SIGCONT)?; + child.signal(Signal::SIGCONT as _)?; sleep(DIE_TIME).await; assert!(child.try_wait()?.is_none(), "not exited with sigcont"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME).await; assert!(child.try_wait()?.is_some(), "exited with sigterm"); @@ -26,11 +26,11 @@ async fn process_group() -> Result<()> { .wrap(ProcessGroup::leader()) .spawn()?; - child.signal(Signal::SIGCONT)?; + child.signal(Signal::SIGCONT as _)?; sleep(DIE_TIME).await; assert!(child.try_wait()?.is_none(), "not exited with sigcont"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME).await; assert!(child.try_wait()?.is_some(), "exited with sigterm"); @@ -45,11 +45,11 @@ async fn process_session() -> Result<()> { .wrap(ProcessSession) .spawn()?; - child.signal(Signal::SIGCONT)?; + child.signal(Signal::SIGCONT as _)?; sleep(DIE_TIME).await; assert!(child.try_wait()?.is_none(), "not exited with sigcont"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME).await; assert!(child.try_wait()?.is_some(), "exited with sigterm"); diff --git a/tests/tokio_unix/try_wait_twice_after_sigterm.rs b/tests/tokio_unix/try_wait_twice_after_sigterm.rs index 789de5a..39a0415 100644 --- a/tests/tokio_unix/try_wait_twice_after_sigterm.rs +++ b/tests/tokio_unix/try_wait_twice_after_sigterm.rs @@ -8,7 +8,7 @@ async fn nowrap() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME).await; assert!(child.try_wait()?.is_some(), "try_wait() one"); @@ -27,7 +27,7 @@ async fn process_group() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME).await; assert!(child.try_wait()?.is_some(), "try_wait() one"); @@ -46,7 +46,7 @@ async fn process_session() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; sleep(DIE_TIME).await; assert!(child.try_wait()?.is_some(), "try_wait() one"); diff --git a/tests/tokio_unix/wait_twice_after_sigterm.rs b/tests/tokio_unix/wait_twice_after_sigterm.rs index 7949fb4..2b2e7d7 100644 --- a/tests/tokio_unix/wait_twice_after_sigterm.rs +++ b/tests/tokio_unix/wait_twice_after_sigterm.rs @@ -8,7 +8,7 @@ async fn nowrap() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; let status = Box::into_pin(child.wait()).await?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() one"); @@ -28,7 +28,7 @@ async fn process_group() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; let status = Box::into_pin(child.wait()).await?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() one"); @@ -48,7 +48,7 @@ async fn process_session() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre sigterm"); - child.signal(Signal::SIGTERM)?; + child.signal(Signal::SIGTERM as _)?; let status = Box::into_pin(child.wait()).await?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() one");