Skip to content

timeout: cleanups #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Because it is a FAQ, the major differences between this project and uutils are:
- [x] strip (Development)
- [x] tail
- [x] time
- [x] timeout
- [x] tr
- [x] true
- [x] uncompress (compress cat.)
Expand Down Expand Up @@ -218,7 +219,6 @@ Because it is a FAQ, the major differences between this project and uutils are:
- [ ] sed
- [ ] sh -- Volunteer starting point at https://github.com/rustcoreutils/posixutils-rs/tree/shell
- [ ] talk (status: in progress)
- [ ] timeout (status: in progress)

## Installation

Expand Down
29 changes: 9 additions & 20 deletions process/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;
use std::{
error::Error,
Expand Down Expand Up @@ -102,39 +102,28 @@ static KILL_AFTER: Mutex<Option<Duration>> = Mutex::new(None);
static MONITORED_PID: AtomicI32 = AtomicI32::new(0);
static TIMED_OUT: AtomicBool = AtomicBool::new(false);

/// timeout — execute a utility with a time limit
#[derive(Parser)]
#[command(version, about)]
#[command(version, about = gettext("timeout — execute a utility with a time limit"))]
struct Args {
/// Only time out the utility itself, not its descendants.
#[arg(short = 'f', long)]
#[arg(short = 'f', long, help=gettext("Only time out the utility itself, not its descendants."))]
foreground: bool,

/// Always preserve (mimic) the wait status of the executed utility, even if the time limit was reached.
#[arg(short = 'p', long)]
#[arg(short = 'p', long, help=gettext("Preserve the exit status of the utility."))]
preserve_status: bool,

/// Send a SIGKILL signal if the child process created to execute the utility has not terminated after the time period
/// specified by time has elapsed since the first signal was sent. The value of time shall be interpreted as specified for
/// the duration operand.
#[arg(short = 'k', long, value_parser = parse_duration)]
#[arg(short = 'k', long, value_parser = parse_duration, help=gettext("Send a SIGKILL signal if the child process has not terminated after the time period."))]
kill_after: Option<Duration>,

/// Specify the signal to send when the time limit is reached, using one of the symbolic names defined in the <signal.h> header.
/// Values of signal shall be recognized in a case-independent fashion, without the SIG prefix. By default, SIGTERM shall be sent.
#[arg(short = 's', long, default_value = "TERM", value_parser = parse_signal)]
#[arg(short = 's', long, default_value = "TERM", value_parser = parse_signal, help=gettext("Specify the signal to send when the time limit is reached."))]
signal_name: i32,

/// The maximum amount of time to allow the utility to run, specified as a decimal number with an optional decimal fraction and an optional suffix.
#[arg(name = "DURATION", value_parser = parse_duration)]
#[arg(name = "DURATION", value_parser = parse_duration, help=gettext("The maximum amount of time to allow the utility to run, specified as a decimal number with an optional decimal fraction and an optional suffix."))]
duration: Duration,

/// The name of a utility that is to be executed.
#[arg(name = "UTILITY")]
#[arg(name = "UTILITY", help=gettext("The utility to execute."))]
utility: String,

/// Any string to be supplied as an argument when executing the utility named by the utility operand.
#[arg(name = "ARGUMENT", trailing_var_arg = true)]
#[arg(name = "ARGUMENT", trailing_var_arg = true, help=gettext("Arguments to pass to the utility."))]
arguments: Vec<String>,
}

Expand Down