Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/uu/timeout/src/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ use uucore::{
signals::{signal_by_name_or_value, signal_name_by_value},
};

use nix::sys::signal::{Signal, kill};
use nix::unistd::{Pid, getpid, setpgid};

pub mod options {
pub static FOREGROUND: &str = "foreground";
pub static KILL_AFTER: &str = "kill-after";
Expand Down Expand Up @@ -293,8 +296,8 @@ fn preserve_signal_info(signal: libc::c_int) -> libc::c_int {
// The easiest way to preserve the latter seems to be to kill
// ourselves with whatever signal our child exited with, which is
// what the following is intended to accomplish.
unsafe {
libc::kill(libc::getpid(), signal);
if let Ok(sig) = Signal::try_from(signal) {
let _ = kill(getpid(), Some(sig));
}
signal
}
Expand All @@ -315,7 +318,7 @@ fn timeout(
verbose: bool,
) -> UResult<()> {
if !foreground {
unsafe { libc::setpgid(0, 0) };
let _ = setpgid(Pid::from_raw(0), Pid::from_raw(0));
}
#[cfg(unix)]
enable_pipe_errors()?;
Expand Down
Loading