diff options
author | Pascal Terjan <pterjan@mandriva.org> | 2010-01-12 14:02:24 +0000 |
---|---|---|
committer | Pascal Terjan <pterjan@mandriva.org> | 2010-01-12 14:02:24 +0000 |
commit | c9caf51ec391bed1446ae5f27ed02c6283e7560f (patch) | |
tree | 32ffc6a20942d26a7f1461a5e4397921e74150e6 /lib/MDK/Common/System.pm | |
parent | 5971b5dcc8d0a38ebdfd628153cec525b0d1f8b8 (diff) | |
download | perl-MDK-Common-c9caf51ec391bed1446ae5f27ed02c6283e7560f.tar perl-MDK-Common-c9caf51ec391bed1446ae5f27ed02c6283e7560f.tar.gz perl-MDK-Common-c9caf51ec391bed1446ae5f27ed02c6283e7560f.tar.bz2 perl-MDK-Common-c9caf51ec391bed1446ae5f27ed02c6283e7560f.tar.xz perl-MDK-Common-c9caf51ec391bed1446ae5f27ed02c6283e7560f.zip |
fix whereis_binary to work on absolute symlinks inside chroot1.2.24
Diffstat (limited to 'lib/MDK/Common/System.pm')
-rw-r--r-- | lib/MDK/Common/System.pm | 22 |
1 files changed, 21 insertions, 1 deletions
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; } } |