mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
timeout: disable timeout if it is set to zero
This commit is contained in:
parent
8e0ed2d20e
commit
0f9bc8e974
3 changed files with 20 additions and 4 deletions
|
@ -214,10 +214,6 @@ fn timeout(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
if kill_after == Duration::new(0, 0) {
|
|
||||||
// XXX: this may not be right
|
|
||||||
return 124;
|
|
||||||
}
|
|
||||||
if verbose {
|
if verbose {
|
||||||
show_error!("sending signal KILL to command '{}'", cmd[0]);
|
show_error!("sending signal KILL to command '{}'", cmd[0]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ pub trait ChildExt {
|
||||||
fn send_signal(&mut self, signal: usize) -> io::Result<()>;
|
fn send_signal(&mut self, signal: usize) -> io::Result<()>;
|
||||||
|
|
||||||
/// Wait for a process to finish or return after the specified duration.
|
/// Wait for a process to finish or return after the specified duration.
|
||||||
|
/// A `timeout` of zero disables the timeout.
|
||||||
fn wait_or_timeout(&mut self, timeout: Duration) -> io::Result<Option<ExitStatus>>;
|
fn wait_or_timeout(&mut self, timeout: Duration) -> io::Result<Option<ExitStatus>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +107,11 @@ impl ChildExt for Child {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wait_or_timeout(&mut self, timeout: Duration) -> io::Result<Option<ExitStatus>> {
|
fn wait_or_timeout(&mut self, timeout: Duration) -> io::Result<Option<ExitStatus>> {
|
||||||
|
if timeout == Duration::from_micros(0) {
|
||||||
|
return self
|
||||||
|
.wait()
|
||||||
|
.map(|status| Some(ExitStatus::from_std_status(status)));
|
||||||
|
}
|
||||||
// .try_wait() doesn't drop stdin, so we do it manually
|
// .try_wait() doesn't drop stdin, so we do it manually
|
||||||
drop(self.stdin.take());
|
drop(self.stdin.take());
|
||||||
|
|
||||||
|
|
|
@ -31,3 +31,17 @@ fn test_verbose() {
|
||||||
.stderr_only("timeout: sending signal EXIT to command 'sleep'\ntimeout: sending signal KILL to command 'sleep'");
|
.stderr_only("timeout: sending signal EXIT to command 'sleep'\ntimeout: sending signal KILL to command 'sleep'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_zero_timeout() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-v", "0", "sleep", ".1"])
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr()
|
||||||
|
.no_stdout();
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-v", "0", "-s0", "-k0", "sleep", ".1"])
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr()
|
||||||
|
.no_stdout();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue