From 2c945e4c87cc966eaf6a50b65c71f0f9f6a3f1e0 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Tue, 21 Sep 2021 14:17:27 +0200 Subject: [PATCH] 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 --- mmdebstrap | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/mmdebstrap b/mmdebstrap index a1c039e..6e70aa2 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -2697,17 +2697,6 @@ sub run_prepare { $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 = (); if (defined $ENV{LD_LIBRARY_PATH} && $ENV{LD_LIBRARY_PATH} ne "") { @@ -2715,15 +2704,34 @@ sub run_prepare { } # FIXME: workaround allowing installation of systemd should # live in fakechroot, see #917920 - push @ldlibpath, "/lib/systemd"; - foreach my $fname (@ldsoconf) { - open my $fh, "<", $fname - or error "cannot open $fname for reading: $!"; - while (my $line = <$fh>) { - next if $line !~ /^\//; - push @ldlibpath, $line; + push @ldlibpath, "$options->{root}/lib/systemd"; + my $parse_ld_so_conf; + $parse_ld_so_conf = sub { + foreach my $conf (@_) { + next if !-r $conf; + open my $fh, '<', "$conf" or error "can't read $conf: $!"; + while (my $line = <$fh>) { + chomp $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) $ENV{LD_LIBRARY_PATH} = join ':', @ldlibpath; @@ -6483,9 +6491,8 @@ fakeroot.env> and use C later when entering the chroot with C. This mode will not work if maintainer scripts are unable to handle C correctly like the package B until version 0.132. This mode will also not work -with a different libc inside the chroot than on the outside. Since ldconfig -cannot run under fakechroot, the final system will not contain -F. See the section B in B. +with a different libc inside the chroot than on the outside. See the section +B in B. =item B