RunCommand: ensure we reset the umask

This commit is contained in:
Cole Helbling 2022-01-31 11:39:16 -08:00
parent 34e4c119f4
commit 8c67e32480

View file

@ -8,6 +8,7 @@ use JSON::MaybeXS;
use File::Basename qw(dirname);
use File::Path qw(make_path);
use IPC::Run3;
use Try::Tiny;
sub isEnabled {
my ($self) = @_;
@ -166,20 +167,28 @@ sub buildFinished {
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog) or die "RunCommandLog not found.";
my $dir = dirname($logPath);
my $oldUmask = umask();
my $f;
# file: 640, dir: 750
umask(0027);
make_path($dir);
try {
# file: 640, dir: 750
umask(0027);
make_path($dir);
open(my $f, '>', $logPath);
umask($oldUmask);
open($f, '>', $logPath);
umask($oldUmask);
run3($command, \undef, $f, $f, { return_if_system_error => 1 }) == 1
or warn "notification command '$command' failed with exit status $? ($!)\n";
run3($command, \undef, $f, $f, { return_if_system_error => 1 }) == 1
or warn "notification command '$command' failed with exit status $? ($!)\n";
close($f);
close($f);
$runlog->completed_with_child_error($?, $!);
$runlog->completed_with_child_error($?, $!);
1;
} catch {
die "Died while trying to process RunCommand (${\$runlog->uuid}): $_";
} finally {
umask($oldUmask);
};
}
}