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
12 changes: 12 additions & 0 deletions src/uu/kill/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
kill-about = Send signal to processes or list information about signals.
kill-usage = kill [OPTIONS]... PID...

# Help messages
kill-help-list = Lists signals
kill-help-table = Lists table of signals
kill-help-signal = Sends given signal instead of SIGTERM

# Error messages
kill-error-no-process-id = no process ID specified
Try --help for more information.
kill-error-invalid-signal = { $signal }: invalid signal
kill-error-parse-argument = failed to parse argument { $argument }: { $error }
kill-error-sending-signal = sending signal to { $pid } failed
14 changes: 14 additions & 0 deletions src/uu/kill/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kill-about = Envoyer un signal aux processus ou lister les informations sur les signaux.
kill-usage = kill [OPTIONS]... PID...

# Messages d'aide
kill-help-list = Liste les signaux
kill-help-table = Liste le tableau des signaux
kill-help-signal = Envoie le signal donné au lieu de SIGTERM

# Messages d'erreur
kill-error-no-process-id = aucun ID de processus spécifié
Essayez --help pour plus d'informations.
kill-error-invalid-signal = { $signal } : signal invalide
kill-error-parse-argument = échec de l'analyse de l'argument { $argument } : { $error }
kill-error-sending-signal = échec de l'envoi du signal au processus { $pid }
47 changes: 33 additions & 14 deletions src/uu/kill/src/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
use clap::{Arg, ArgAction, Command};
use nix::sys::signal::{self, Signal};
use nix::unistd::Pid;
use std::collections::HashMap;
use std::io::Error;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::locale::{get_message, get_message_with_args};
use uucore::signals::{ALL_SIGNALS, signal_by_name_or_value, signal_name_by_value};
use uucore::{format_usage, show};

use uucore::locale::get_message;

// When the -l option is selected, the program displays the type of signal related to a certain
// value or string. In case of a value, the program should control the lower 8 bits, but there is
// a particular case in which if the value is in range [128, 159], it is translated to a signal
Expand Down Expand Up @@ -81,8 +81,7 @@
if pids.is_empty() {
Err(USimpleError::new(
1,
"no process ID specified\n\
Try --help for more information.",
get_message("kill-error-no-process-id"),
))
} else {
kill(sig, &pids);
Expand Down Expand Up @@ -111,7 +110,7 @@
Arg::new(options::LIST)
.short('l')
.long(options::LIST)
.help("Lists signals")
.help(get_message("kill-help-list"))
.conflicts_with(options::TABLE)
.action(ArgAction::SetTrue),
)
Expand All @@ -120,7 +119,7 @@
.short('t')
.short_alias('L')
.long(options::TABLE)
.help("Lists table of signals")
.help(get_message("kill-help-table"))
.action(ArgAction::SetTrue),
)
.arg(
Expand All @@ -129,7 +128,7 @@
.short_alias('n') // For bash compatibility, like in GNU coreutils
.long(options::SIGNAL)
.value_name("signal")
.help("Sends given signal instead of SIGTERM")
.help(get_message("kill-help-signal"))
.conflicts_with_all([options::LIST, options::TABLE]),
)
.arg(
Expand Down Expand Up @@ -192,7 +191,13 @@
}
Err(USimpleError::new(
1,
format!("{}: invalid signal", signal_name_or_value.quote()),
get_message_with_args(
"kill-error-invalid-signal",
HashMap::from([(
"signal".to_string(),
signal_name_or_value.quote().to_string(),
)]),
),
))
}

Expand Down Expand Up @@ -220,7 +225,10 @@
Some(x) => Ok(x),
None => Err(USimpleError::new(
1,
format!("{}: invalid signal", signal_name.quote()),
get_message_with_args(
"kill-error-invalid-signal",
HashMap::from([("signal".to_string(), signal_name.quote().to_string())]),
),
)),
}
}
Expand All @@ -229,7 +237,16 @@
pids.iter()
.map(|x| {
x.parse::<i32>().map_err(|e| {
USimpleError::new(1, format!("failed to parse argument {}: {e}", x.quote()))
USimpleError::new(
1,
get_message_with_args(
"kill-error-parse-argument",
HashMap::from([
("argument".to_string(), x.quote().to_string()),
("error".to_string(), e.to_string()),
]),
),
)

Check warning on line 249 in src/uu/kill/src/kill.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/kill/src/kill.rs#L240-L249

Added lines #L240 - L249 were not covered by tests
})
})
.collect()
Expand All @@ -238,10 +255,12 @@
fn kill(sig: Option<Signal>, pids: &[i32]) {
for &pid in pids {
if let Err(e) = signal::kill(Pid::from_raw(pid), sig) {
show!(
Error::from_raw_os_error(e as i32)
.map_err_context(|| format!("sending signal to {pid} failed"))
);
show!(Error::from_raw_os_error(e as i32).map_err_context(|| {
get_message_with_args(
"kill-error-sending-signal",
HashMap::from([("pid".to_string(), pid.to_string())]),

Check warning on line 261 in src/uu/kill/src/kill.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/kill/src/kill.rs#L258-L261

Added lines #L258 - L261 were not covered by tests
)
}));

Check warning on line 263 in src/uu/kill/src/kill.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/kill/src/kill.rs#L263

Added line #L263 was not covered by tests
}
}
}
Loading