Skip to content

Commit

Permalink
api: remove nix types from public API
Browse files Browse the repository at this point in the history
  • Loading branch information
passcod committed Apr 16, 2024
1 parent 35270b8 commit 7de6ac0
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 39 deletions.
1 change: 1 addition & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
6 changes: 3 additions & 3 deletions src/std/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 8 additions & 6 deletions src/std/process_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _),
}
}
}

Expand All @@ -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 _
}
}

Expand Down Expand Up @@ -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)?)
}
}
4 changes: 2 additions & 2 deletions src/tokio/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/tokio/process_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
}
}

Expand Down Expand Up @@ -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)?)
}
}
12 changes: 6 additions & 6 deletions tests/std_unix/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand Down
6 changes: 3 additions & 3 deletions tests/std_unix/try_wait_twice_after_sigterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand Down
6 changes: 3 additions & 3 deletions tests/std_unix/wait_twice_after_sigterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down
12 changes: 6 additions & 6 deletions tests/tokio_unix/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand Down
6 changes: 3 additions & 3 deletions tests/tokio_unix/try_wait_twice_after_sigterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand Down
6 changes: 3 additions & 3 deletions tests/tokio_unix/wait_twice_after_sigterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down

0 comments on commit 7de6ac0

Please sign in to comment.