mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 15:22:38 +00:00
timeout: disable pre-existing SIGCHLD handlers
Needed to make a GNU test pass
This commit is contained in:
parent
0f9bc8e974
commit
b4efd5a749
3 changed files with 17 additions and 1 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "Inflector"
|
||||
version = "0.11.4"
|
||||
|
@ -2606,6 +2608,7 @@ version = "0.0.6"
|
|||
dependencies = [
|
||||
"clap",
|
||||
"libc",
|
||||
"nix 0.20.0",
|
||||
"uucore",
|
||||
"uucore_procs",
|
||||
]
|
||||
|
|
|
@ -17,6 +17,7 @@ path = "src/timeout.rs"
|
|||
[dependencies]
|
||||
clap = "2.33"
|
||||
libc = "0.2.42"
|
||||
nix = "0.20.0"
|
||||
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["parse_time", "process", "signals"] }
|
||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// * 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
|
||||
// spell-checker:ignore (ToDO) tstr sigstr cmdname setpgid sigchld
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
@ -161,6 +161,17 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
)
|
||||
}
|
||||
|
||||
/// Remove pre-existing SIGCHLD handlers that would make waiting for the child's exit code fail.
|
||||
fn unblock_sigchld() {
|
||||
unsafe {
|
||||
nix::sys::signal::signal(
|
||||
nix::sys::signal::Signal::SIGCHLD,
|
||||
nix::sys::signal::SigHandler::SigDfl,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: Improve exit codes, and make them consistent with the GNU Coreutils exit codes.
|
||||
|
||||
fn timeout(
|
||||
|
@ -194,6 +205,7 @@ fn timeout(
|
|||
}
|
||||
}
|
||||
};
|
||||
unblock_sigchld();
|
||||
match process.wait_or_timeout(duration) {
|
||||
Ok(Some(status)) => status.code().unwrap_or_else(|| status.signal().unwrap()),
|
||||
Ok(None) => {
|
||||
|
|
Loading…
Reference in a new issue