summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@mandriva.org>2010-01-12 14:02:24 +0000
committerPascal Terjan <pterjan@mandriva.org>2010-01-12 14:02:24 +0000
commitc9caf51ec391bed1446ae5f27ed02c6283e7560f (patch)
tree32ffc6a20942d26a7f1461a5e4397921e74150e6
parent5971b5dcc8d0a38ebdfd628153cec525b0d1f8b8 (diff)
downloadperl-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
-rw-r--r--NEWS4
-rw-r--r--lib/MDK/Common.pm.pl2
-rw-r--r--lib/MDK/Common/System.pm22
3 files changed, 26 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 39329a9..ae4d778 100644
--- a/NEWS
+++ b/NEWS
@@ -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;
}
}