cleanup leftovers in /tmp inside the chroot

This commit is contained in:
Johannes 'josch' Schauer 2020-01-06 12:44:44 +01:00
parent 61db086921
commit c6944d0b8f
Signed by: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -1877,6 +1877,26 @@ sub setup {
}
unlink $path or error "cannot unlink $path: $!";
}
# remove any possible leftovers in /tmp but warn about it
if (-d "$options->{root}/tmp") {
opendir(my $dh, "$options->{root}/tmp") or error "Can't opendir($options->{root}/tmp): $!";
while (my $entry = readdir $dh) {
# skip the "." and ".." entries
next if $entry eq ".";
next if $entry eq "..";
warning "deleting files in /tmp: $entry";
remove_tree("$options->{root}/tmp/$entry", {error => \my $err});
if (@$err) {
for my $diag (@$err) {
my ($file, $message) = %$diag;
if ($file eq '') { warning "general error: $message"; }
else { warning "problem unlinking $file: $message"; }
}
}
}
closedir($dh);
}
}
# messages from process inside unshared namespace to the outside