diff options
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | lib/MDK/Common.pm.pl | 2 | ||||
-rw-r--r-- | lib/MDK/Common/System.pm | 22 |
3 files changed, 26 insertions, 2 deletions
@@ -1,3 +1,7 @@ +Version 1.2.24 - 12 January 2010, by Pascal Terjan + +- fix whereis_binary to work on absolute symlinks inside chroot + Version 1.2.23 - 14 December 2009, by Pascal Terjan - get available size of requested partition not / in df 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; } } |