don't copy in qemu-user-static if we don't need to

This commit is contained in:
Johannes Schauer Marin Rodrigues 2022-01-08 08:28:17 +01:00
parent 8bc6a4daa9
commit 388c7980d3
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -2514,6 +2514,27 @@ sub run_prepare {
$ENV{QEMU_LD_PREFIX} = $options->{root}; $ENV{QEMU_LD_PREFIX} = $options->{root};
} }
} elsif (any { $_ eq $options->{mode} } ('root', 'unshare')) { } elsif (any { $_ eq $options->{mode} } ('root', 'unshare')) {
my $require_qemu_static = 1;
# make $@ local, so we don't print an eventual error
# in other parts where we evaluate $@
local $@ = '';
eval {
# Check for the F flag which makes the kernel open the binfmt
# binary at configuration time instead of lazily at startup
# time. If the flag is set, then the qemu-static binary is not
# required inside the chroot.
open my $fh, '<',
"/proc/sys/fs/binfmt_misc/qemu-$options->{qemu}";
while (my $line = <$fh>) {
chomp($line);
if ($line =~ /^flags: [A-Z]*F[A-Z]*$/) {
$require_qemu_static = 0;
last;
}
}
close $fh;
};
if ($require_qemu_static) {
# other modes require a static qemu-user binary # other modes require a static qemu-user binary
my $qemubin = "/usr/bin/qemu-$options->{qemu}-static"; my $qemubin = "/usr/bin/qemu-$options->{qemu}-static";
if (!-e $qemubin) { if (!-e $qemubin) {
@ -2527,6 +2548,7 @@ sub run_prepare {
# fail with EACCES # fail with EACCES
chmod 0755, "$options->{root}/$qemubin" chmod 0755, "$options->{root}/$qemubin"
or error "cannot chmod $qemubin: $!"; or error "cannot chmod $qemubin: $!";
}
} else { } else {
error "unknown mode: $options->{mode}"; error "unknown mode: $options->{mode}";
} }
@ -2875,8 +2897,11 @@ sub run_cleanup() {
or error "failed to unlink $ENV{APT_CONFIG}: $!"; or error "failed to unlink $ENV{APT_CONFIG}: $!";
} }
if (defined $options->{qemu} if (any { $_ eq 'cleanup/mmdebstrap/qemu' } @{ $options->{skip} }) {
and any { $_ eq $options->{mode} } ('root', 'unshare')) { info "skipping cleanup/mmdebstrap/qume as requested";
} elsif (defined $options->{qemu}
and any { $_ eq $options->{mode} } ('root', 'unshare')
and -e "$options->{root}/usr/bin/qemu-$options->{qemu}-static") {
unlink "$options->{root}/usr/bin/qemu-$options->{qemu}-static" unlink "$options->{root}/usr/bin/qemu-$options->{qemu}-static"
or error or error
"cannot unlink /usr/bin/qemu-$options->{qemu}-static: $!"; "cannot unlink /usr/bin/qemu-$options->{qemu}-static: $!";