From bf3c46ed439abc3008f1889e490c8dd379739e4a Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 25 Jan 2022 10:33:01 -0800 Subject: [PATCH] RunCommand: use IPC::Run to spawn the command This allows `logPath`s with spaces and other characters that might otherwise cause problems inside a `system()` call. --- src/lib/Hydra/Plugin/RunCommand.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/Hydra/Plugin/RunCommand.pm b/src/lib/Hydra/Plugin/RunCommand.pm index 084e0dd8..93af65dc 100644 --- a/src/lib/Hydra/Plugin/RunCommand.pm +++ b/src/lib/Hydra/Plugin/RunCommand.pm @@ -9,6 +9,7 @@ use Digest::SHA1 qw(sha1_hex); use Hydra::Model::DB; use Hydra::Helper::Nix; use File::Basename qw(dirname); +use IPC::Run; sub isEnabled { my ($self) = @_; @@ -174,14 +175,15 @@ sub buildFinished { mkdir($dir); open(my $f, '>', $logPath); - close($f); - umask($oldUmask); - # Run the command - system("$command 1>$logpath 2>&1") == 0 + my $stdin = ""; + my @cmd = ["sh", "-c", $command]; + IPC::Run::run(@cmd, \$stdin, $f, '2>&1') == 1 or warn "notification command '$command' failed with exit status $? ($!)\n"; + close($f); + $runlog->completed_with_child_error($?, $!); } }