From 09cfd429c98f55e19626bd33c5bc8b0a51bca3db Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Sun, 8 Jul 2007 22:11:49 +0000 Subject: [PATCH] Dpkg::Shlibs.pm: Code cleanup Use the new Dpkg::* utility modules Don't allow infinite recursion in parse_ldso_conf General cleanup --- scripts/Dpkg/Shlibs.pm | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/scripts/Dpkg/Shlibs.pm b/scripts/Dpkg/Shlibs.pm index c9e88499..e52c6e72 100644 --- a/scripts/Dpkg/Shlibs.pm +++ b/scripts/Dpkg/Shlibs.pm @@ -14,18 +14,24 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +package Dpkg::Shlibs; + use strict; use warnings; -require 'dpkg-gettext.pl'; +use base qw(Exporter); +our @EXPORT_OK = qw(@librarypaths find_library); -use IO::File; +use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(syserr); +use Dpkg::Shlibs::Objdump; -use Exporter 'import'; -our @EXPORT_OK = qw(@librarypaths find_library); +textdomain("dpkg-dev"); -our @librarypaths = qw(/lib /usr/lib /lib32 /usr/lib32 /lib64 /usr/lib64 - /emul/ia32-linux/lib /emul/ia32-linux/usr/lib); +use constant DEFAULT_LIBRARY_PATH => + qw(/lib /usr/lib /lib32 /usr/lib32 /lib64 /usr/lib64 + /emul/ia32-linux/lib /emul/ia32-linux/usr/lib); +our @librarypaths = (DEFAULT_LIBRARY_PATH); # Update library paths with LD_LIBRARY_PATH if ($ENV{LD_LIBRARY_PATH}) { @@ -40,18 +46,20 @@ if ($ENV{LD_LIBRARY_PATH}) { # Update library paths with ld.so config parse_ldso_conf("/etc/ld.so.conf") if -e "/etc/ld.so.conf"; +my %visited; sub parse_ldso_conf { my $file = shift; - my $fh = new IO::File; - $fh->open($file, "<") - or main::syserr(sprintf(_g("couldn't open %s: %s"), $file, $!)); + open my $fh, "<", $file + or syserr(sprintf(_g("couldn't open %s"), $file)); + $visited{$file}++; while (<$fh>) { next if /^\s*$/; chomp; s{/+$}{}; if (/^include\s+(\S.*\S)\s*$/) { foreach my $include (glob($1)) { - parse_ldso_conf($include) if -e $include; + parse_ldso_conf($include) if -e $include + && !$visited{$include}; } } elsif (m{^\s*/}) { s/^\s+//; @@ -61,7 +69,7 @@ sub parse_ldso_conf { } } } - $fh->close; + close $fh or syserr(sprintf(_g("couldn't close %s"), $file));; } # find_library ($soname, \@rpath, $format, $root) -- 2.39.5