Hydra::Helper::Nix: expose a captureStdoutStderrWithStdin, make it available in tests

This commit is contained in:
Graham Christensen
2022-01-21 09:23:48 -05:00
parent d4fe7e55dd
commit 3a6c25489c
3 changed files with 19 additions and 2 deletions

View File

@ -18,6 +18,7 @@ our @ISA = qw(Exporter);
our @EXPORT = qw(
cancelBuilds
captureStdoutStderr
captureStdoutStderrWithStdin
findLog
gcRootFor
getBaseUrl
@ -428,14 +429,19 @@ sub pathIsInsidePrefix {
sub captureStdoutStderr {
my ($timeout, @cmd) = @_;
my $stdin = "";
return captureStdoutStderrWithStdin($timeout, \@cmd, "");
}
sub captureStdoutStderrWithStdin {
my ($timeout, $cmd, $stdin) = @_;
my $stdout;
my $stderr;
eval {
local $SIG{ALRM} = sub { die "timeout\n" }; # NB: \n required
alarm $timeout;
IPC::Run::run(\@cmd, \$stdin, \$stdout, \$stderr);
IPC::Run::run($cmd, \$stdin, \$stdout, \$stderr);
alarm 0;
1;
} or do {