Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/uu/timeout/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ timeout-after-help = Upon timeout, send the TERM signal to COMMAND, if no other
# Error messages
timeout-error-invalid-signal = { $signal }: invalid signal
timeout-error-failed-to-execute-process = failed to execute process: { $error }
timeout-error-monitor-exited-before-child-exec = timeout monitor exited before child exec

# Verbose messages
timeout-verbose-sending-signal = sending signal { $signal } to command { $command }
1 change: 1 addition & 0 deletions src/uu/timeout/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ timeout-after-help = À l'expiration du délai, le signal TERM est envoyé à CO
# Messages d'erreur
timeout-error-invalid-signal = { $signal } : signal invalide
timeout-error-failed-to-execute-process = échec d'exécution du processus : { $error }
timeout-error-monitor-exited-before-child-exec = le processus de délai s'est terminé avant l'exécution du processus enfant

# Messages détaillés
timeout-verbose-sending-signal = envoi du signal { $signal } à la commande { $command }
13 changes: 10 additions & 3 deletions src/uu/timeout/src/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore (ToDO) tstr sigstr cmdname setpgid sigchld getpid
// spell-checker:ignore (ToDO) tstr sigstr cmdname setpgid sigchld getpid getppid

mod status;

use crate::status::ExitStatus;
use clap::{Arg, ArgAction, Command};
use std::io::{ErrorKind, Write};
use std::io::{Error, ErrorKind, Write};
use std::os::unix::process::ExitStatusExt;
use std::process::{self, Child, Stdio};
use std::sync::atomic::{self, AtomicBool};
Expand All @@ -26,7 +26,7 @@ use uucore::{
};

use nix::sys::signal::{SigHandler, Signal, kill};
use nix::unistd::{Pid, getpid, setpgid};
use nix::unistd::{Pid, getpid, getppid, setpgid};
#[cfg(unix)]
use std::os::unix::process::CommandExt;

Expand Down Expand Up @@ -380,6 +380,13 @@ fn timeout(
if let Some(sig) = death_sig {
let _ = nix::sys::prctl::set_pdeathsig(sig);
}
// Close the post-fork race where the timeout monitor can die
// after PDEATHSIG setup but before exec starts the target command.
if getppid().as_raw() == 1 {
return Err(Error::other(
translate!("timeout-error-monitor-exited-before-child-exec"),
));
}
Ok(())
});
}
Expand Down
Loading