also check for situations in which a non-native arch can be executed without emulation

This commit is contained in:
Johannes 'josch' Schauer 2019-09-26 10:14:45 +02:00
parent 3d3d3fe12d
commit d5033dd0d1
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -1951,6 +1951,28 @@ sub main() {
}; };
chomp (my $hostarch = `dpkg --print-architecture`); chomp (my $hostarch = `dpkg --print-architecture`);
if ($hostarch ne $nativearch) { if ($hostarch ne $nativearch) {
my $withemu = 0;
my $noemu = 0;
{
my $pid = open my $fh, '-|' // error "failed to fork(): $!";
if ($pid == 0) {
{
no warnings; # don't print a warning if the following fails
exec 'arch-test', $nativearch;
}
# if exec didn't work (for example because the arch-test program is
# missing) prepare for the worst and assume that the architecture
# cannot be executed
print "$nativearch: not supported on this machine/kernel\n";
exit 1;
}
chomp (my $content = do { local $/; <$fh> });
close $fh;
if ($? == 0 and $content eq "$nativearch: ok") {
$withemu = 1;
}
}
{
my $pid = open my $fh, '-|' // error "failed to fork(): $!"; my $pid = open my $fh, '-|' // error "failed to fork(): $!";
if ($pid == 0) { if ($pid == 0) {
{ {
@ -1965,12 +1987,20 @@ sub main() {
} }
chomp (my $content = do { local $/; <$fh> }); chomp (my $content = do { local $/; <$fh> });
close $fh; close $fh;
if ($? != 0 or $content ne "$nativearch: ok") { if ($? == 0 and $content eq "$nativearch: ok") {
info "$nativearch cannot be executed, falling back to qemu-user"; $noemu = 1;
if (!exists $deb2qemu->{$nativearch}) {
error "no mapping from $nativearch to qemu-user binary";
} }
$options->{qemu} = $deb2qemu->{$nativearch}; }
# four different outcomes, depending on whether arch-test
# succeeded with or without emulation
#
# withemu | noemu |
# --------+-------+-----------------
# 0 | 0 | test why emu doesn't work and quit
# 0 | 1 | should never happen
# 1 | 0 | use qemu emulation
# 1 | 1 | don't use qemu emulation
if ($withemu == 0 and $noemu == 0) {
{ {
open my $fh, '<', '/proc/filesystems' or error "failed to open /proc/filesystems: $!"; open my $fh, '<', '/proc/filesystems' or error "failed to open /proc/filesystems: $!";
unless (grep /^nodev\tbinfmt_misc$/, (<$fh>)) { unless (grep /^nodev\tbinfmt_misc$/, (<$fh>)) {
@ -1993,8 +2023,19 @@ sub main() {
error "qemu-$options->{qemu} is not a supported binfmt name"; error "qemu-$options->{qemu} is not a supported binfmt name";
} }
} }
error "qemu emulation of $nativearch failed for an unknown reason";
} elsif ($withemu == 0 and $noemu == 1) {
error "arch-test succeeded without emu but not with emu";
} elsif ($withemu == 1 and $noemu == 0) {
info "$nativearch cannot be executed, falling back to qemu-user";
if (!exists $deb2qemu->{$nativearch}) {
error "no mapping from $nativearch to qemu-user binary";
}
$options->{qemu} = $deb2qemu->{$nativearch};
} elsif ($withemu == 1 and $noemu == 1) {
info "$nativearch is different from $hostarch but can be executed natively";
} else { } else {
info "$nativearch can be executed on this $hostarch machine"; error "logic error";
} }
} else { } else {
info "chroot architecture $nativearch is equal to the host's architecture"; info "chroot architecture $nativearch is equal to the host's architecture";