improve fakechroot LD_LIBRARY_PATH

- use /etc/ld.so.conf from the chroot instead of the host
 - parse /etc/ld.so.conf instead of blindly accessing /etc/ld.so.conf.d
 - add libraries from the chroot instead of the host
This commit is contained in:
Johannes Schauer Marin Rodrigues 2021-09-21 14:17:27 +02:00
parent f5f6343622
commit 2c945e4c87
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -2697,17 +2697,6 @@ sub run_prepare {
$ENV{FAKECHROOT_AF_UNIX_PATH} = "/tmp"; $ENV{FAKECHROOT_AF_UNIX_PATH} = "/tmp";
} }
{ {
my @ldsoconf = ('/etc/ld.so.conf');
opendir(my $dh, '/etc/ld.so.conf.d')
or error "Can't opendir(/etc/ld.so.conf.d): $!";
while (my $entry = readdir $dh) {
# skip the "." and ".." entries
next if $entry eq ".";
next if $entry eq "..";
next if $entry !~ /\.conf$/;
push @ldsoconf, "/etc/ld.so.conf.d/$entry";
}
closedir($dh);
my @ldlibpath = (); my @ldlibpath = ();
if (defined $ENV{LD_LIBRARY_PATH} if (defined $ENV{LD_LIBRARY_PATH}
&& $ENV{LD_LIBRARY_PATH} ne "") { && $ENV{LD_LIBRARY_PATH} ne "") {
@ -2715,16 +2704,35 @@ sub run_prepare {
} }
# FIXME: workaround allowing installation of systemd should # FIXME: workaround allowing installation of systemd should
# live in fakechroot, see #917920 # live in fakechroot, see #917920
push @ldlibpath, "/lib/systemd"; push @ldlibpath, "$options->{root}/lib/systemd";
foreach my $fname (@ldsoconf) { my $parse_ld_so_conf;
open my $fh, "<", $fname $parse_ld_so_conf = sub {
or error "cannot open $fname for reading: $!"; foreach my $conf (@_) {
next if !-r $conf;
open my $fh, '<', "$conf" or error "can't read $conf: $!";
while (my $line = <$fh>) { while (my $line = <$fh>) {
next if $line !~ /^\//; chomp $line;
push @ldlibpath, $line; if ($line eq "") {
next;
}
if ($line =~ /^#/) {
next;
}
if ($line =~ /include (.*)/) {
$parse_ld_so_conf->(glob("$options->{root}/$1"));
next;
}
if (!-d "$options->{root}/$line") {
next;
}
push @ldlibpath, "$options->{root}/$line";
} }
close $fh; close $fh;
} }
};
if (-e "$options->{root}/etc/ld.so.conf") {
$parse_ld_so_conf->("$options->{root}/etc/ld.so.conf");
}
## no critic (Variables::RequireLocalizedPunctuationVars) ## no critic (Variables::RequireLocalizedPunctuationVars)
$ENV{LD_LIBRARY_PATH} = join ':', @ldlibpath; $ENV{LD_LIBRARY_PATH} = join ':', @ldlibpath;
} }
@ -6483,9 +6491,8 @@ fakeroot.env> and use C<fakeroot.env> later when entering the chroot with
C<fakechroot fakeroot -i fakeroot.env chroot ...>. This mode will not work if C<fakechroot fakeroot -i fakeroot.env chroot ...>. This mode will not work if
maintainer scripts are unable to handle C<LD_PRELOAD> correctly like the maintainer scripts are unable to handle C<LD_PRELOAD> correctly like the
package B<initramfs-tools> until version 0.132. This mode will also not work package B<initramfs-tools> until version 0.132. This mode will also not work
with a different libc inside the chroot than on the outside. Since ldconfig with a different libc inside the chroot than on the outside. See the section
cannot run under fakechroot, the final system will not contain B<LIMITATIONS> in B<fakechroot(1)>.
F</etc/ld.so.cache>. See the section B<LIMITATIONS> in B<fakechroot(1)>.
=item B<proot> =item B<proot>