From c9caf51ec391bed1446ae5f27ed02c6283e7560f Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Tue, 12 Jan 2010 14:02:24 +0000 Subject: fix whereis_binary to work on absolute symlinks inside chroot --- lib/MDK/Common.pm.pl | 2 +- lib/MDK/Common/System.pm | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/MDK/Common.pm.pl b/lib/MDK/Common.pm.pl index e7d63c3..4a490f5 100644 --- a/lib/MDK/Common.pm.pl +++ b/lib/MDK/Common.pm.pl @@ -73,7 +73,7 @@ our @ISA = qw(Exporter); # perl_checker: RE-EXPORT-ALL our @EXPORT = map { @$_ } map { values %{'MDK::Common::' . $_ . 'EXPORT_TAGS'} } grep { /::$/ } keys %MDK::Common::; -our $VERSION = "1.2.23"; +our $VERSION = "1.2.24"; 1; EOF diff --git a/lib/MDK/Common/System.pm b/lib/MDK/Common/System.pm index 776c888..eac08ee 100644 --- a/lib/MDK/Common/System.pm +++ b/lib/MDK/Common/System.pm @@ -319,6 +319,17 @@ sub availableRamMB() { 4 * MDK::Common::Math::round((-s '/proc/kcore') / 1024 / sub gettimeofday() { my $t = pack "LL"; syscall_('gettimeofday', $t, 0) or die "gettimeofday failed: $!\n"; unpack("LL", $t) } sub unix2dos { local $_ = $_[0]; s/\015$//mg; s/$/\015/mg; $_ } +sub expandLinkInChroot { + my ($file, $prefix) = @_; + my $l = readlink "$prefix$file"; + return unless $l; + return $l if $l =~ /^\//; + my $path = $file; + $path =~ s!/[^/]*$!!; + $path .= "/$l"; + return $path; +} + sub whereis_binary { my ($prog, $o_prefix) = @_; if ($prog =~ m!/!) { @@ -327,7 +338,16 @@ sub whereis_binary { } foreach (split(':', $ENV{PATH})) { my $f = "$_/$prog"; - -x "$o_prefix$f" and return $f; + my $links = 0; + my $l = $f; + while ( -l "$o_prefix$l" ){ + $l = expandLinkInChroot($l, $o_prefix); + if ($links++ > 16) { + warn qq(symlink recursion too deep in whereis_binary\n); + return; + } + } + -x "$o_prefix$l" and return $f; } } -- cgit v1.2.1