Skip to content
Merged
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
14 changes: 14 additions & 0 deletions src/uu/timeout/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
timeout-about = Start COMMAND, and kill it if still running after DURATION.
timeout-usage = timeout [OPTION] DURATION COMMAND...

# Help messages
timeout-help-foreground = when not running timeout directly from a shell prompt, allow COMMAND to read from the TTY and get TTY signals; in this mode, children of COMMAND will not be timed out
timeout-help-kill-after = also send a KILL signal if COMMAND is still running this long after the initial signal was sent
timeout-help-preserve-status = exit with the same status as COMMAND, even when the command times out
timeout-help-signal = specify the signal to be sent on timeout; SIGNAL may be a name like 'HUP' or a number; see 'kill -l' for a list of signals
timeout-help-verbose = diagnose to stderr any signal sent upon timeout

# Error messages
timeout-error-invalid-signal = { $signal }: invalid signal
timeout-error-failed-to-execute-process = failed to execute process: { $error }

# Verbose messages
timeout-verbose-sending-signal = sending signal { $signal } to command { $command }
16 changes: 16 additions & 0 deletions src/uu/timeout/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
timeout-about = Démarrer COMMANDE, et la tuer si elle fonctionne encore après DURÉE.
timeout-usage = timeout [OPTION] DURÉE COMMANDE...

# Messages d'aide
timeout-help-foreground = quand on n'exécute pas timeout directement depuis une invite de shell, permettre à COMMANDE de lire depuis le TTY et d'obtenir les signaux TTY ; dans ce mode, les enfants de COMMANDE ne seront pas limités dans le temps
timeout-help-kill-after = envoyer aussi un signal KILL si COMMANDE fonctionne encore si longtemps après que le signal initial ait été envoyé
timeout-help-preserve-status = sortir avec le même statut que COMMANDE, même quand la commande dépasse le délai
timeout-help-signal = spécifier le signal à envoyer en cas de délai dépassé ; SIGNAL peut être un nom comme 'HUP' ou un nombre ; voir 'kill -l' pour une liste des signaux
timeout-help-verbose = diagnostiquer vers stderr tout signal envoyé lors d'un dépassement de délai

# Messages d'erreur
timeout-error-invalid-signal = { $signal } : signal invalide
timeout-error-failed-to-execute-process = échec d'exécution du processus : { $error }

# Messages détaillés
timeout-verbose-sending-signal = envoi du signal { $signal } à la commande { $command }
52 changes: 32 additions & 20 deletions src/uu/timeout/src/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use crate::status::ExitStatus;
use clap::{Arg, ArgAction, Command};
use std::collections::HashMap;
use std::io::ErrorKind;
use std::os::unix::process::ExitStatusExt;
use std::process::{self, Child, Stdio};
Expand All @@ -17,7 +18,7 @@
use uucore::parser::parse_time;
use uucore::process::ChildExt;

use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};
#[cfg(unix)]
use uucore::signals::enable_pipe_errors;

Expand Down Expand Up @@ -58,7 +59,13 @@
None => {
return Err(UUsageError::new(
ExitStatus::TimeoutFailed.into(),
format!("{}: invalid signal", signal_.quote()),
get_message_with_args(
"timeout-error-invalid-signal",
HashMap::from([(
"signal".to_string(),
signal_.quote().to_string(),
)]),
),
));
}
Some(signal_value) => signal_value,
Expand Down Expand Up @@ -126,44 +133,34 @@
Arg::new(options::FOREGROUND)
.long(options::FOREGROUND)
.short('f')
.help(
"when not running timeout directly from a shell prompt, allow \
COMMAND to read from the TTY and get TTY signals; in this mode, \
children of COMMAND will not be timed out",
)
.help(get_message("timeout-help-foreground"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::KILL_AFTER)
.long(options::KILL_AFTER)
.short('k')
.help(
"also send a KILL signal if COMMAND is still running this long \
after the initial signal was sent",
),
.help(get_message("timeout-help-kill-after")),
)
.arg(
Arg::new(options::PRESERVE_STATUS)
.long(options::PRESERVE_STATUS)
.short('p')
.help("exit with the same status as COMMAND, even when the command times out")
.help(get_message("timeout-help-preserve-status"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::SIGNAL)
.short('s')
.long(options::SIGNAL)
.help(
"specify the signal to be sent on timeout; SIGNAL may be a name like \
'HUP' or a number; see 'kill -l' for a list of signals",
)
.help(get_message("timeout-help-signal"))
.value_name("SIGNAL"),
)
.arg(
Arg::new(options::VERBOSE)
.short('v')
.long(options::VERBOSE)
.help("diagnose to stderr any signal sent upon timeout")
.help(get_message("timeout-help-verbose"))
.action(ArgAction::SetTrue),
)
.arg(Arg::new(options::DURATION).required(true))
Expand Down Expand Up @@ -192,7 +189,16 @@
fn report_if_verbose(signal: usize, cmd: &str, verbose: bool) {
if verbose {
let s = signal_name_by_value(signal).unwrap();
show_error!("sending signal {s} to command {}", cmd.quote());
show_error!(
"{}",
get_message_with_args(
"timeout-verbose-sending-signal",
HashMap::from([
("signal".to_string(), s.to_string()),
("command".to_string(), cmd.quote().to_string())
])
)
);
}
}

Expand Down Expand Up @@ -315,7 +321,13 @@
// FIXME: this may not be 100% correct...
126
};
USimpleError::new(status_code, format!("failed to execute process: {err}"))
USimpleError::new(
status_code,
get_message_with_args(
"timeout-error-failed-to-execute-process",
HashMap::from([("error".to_string(), err.to_string())]),
),
)

Check warning on line 330 in src/uu/timeout/src/timeout.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/timeout/src/timeout.rs#L324-L330

Added lines #L324 - L330 were not covered by tests
})?;
unblock_sigchld();
// Wait for the child process for the specified time period.
Expand Down Expand Up @@ -364,7 +376,7 @@
Ok(status) => Err(status.into()),
Err(e) => Err(USimpleError::new(
ExitStatus::TimeoutFailed.into(),
format!("{e}"),
e.to_string(),

Check warning on line 379 in src/uu/timeout/src/timeout.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/timeout/src/timeout.rs#L379

Added line #L379 was not covered by tests
)),
}
}
Expand Down
Loading