1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# ex:ts=8 sw=4:
# $OpenBSD: SharedLibs.pm,v 1.40 2009/11/29 10:32:58 espie Exp $
#
# Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
use strict;
use warnings;
use OpenBSD::Paths;
package OpenBSD::PackingElement;
sub mark_available_lib
{
}
package OpenBSD::PackingElement::Lib;
sub mark_available_lib
{
my ($self, $pkgname) = @_;
OpenBSD::SharedLibs::register_lib($self->fullname, $pkgname);
}
package OpenBSD::SharedLibs;
use File::Basename;
use OpenBSD::Error;
my $path;
my @ldconfig = (OpenBSD::Paths->ldconfig);
sub init_path($)
{
my $destdir = shift;
$path={};
if ($destdir ne '') {
unshift @ldconfig, OpenBSD::Paths->chroot, $destdir;
}
open my $fh, "-|", @ldconfig, "-r";
if (defined $fh) {
my $_;
while (<$fh>) {
if (m/^\s*search directories:\s*(.*?)\s*$/o) {
for my $d (split(/\:/o, $1)) {
$path->{$d} = 1;
}
last;
}
}
close($fh);
} else {
print STDERR "Can't find ldconfig\n";
}
}
sub mark_ldconfig_directory
{
my ($name, $destdir) = @_;
if (!defined $path) {
init_path($destdir);
}
my $d = dirname($name);
if ($path->{$d}) {
$OpenBSD::PackingElement::Lib::todo = 1;
}
}
sub ensure_ldconfig
{
my $state = shift;
$state->vsystem(@ldconfig, "-R") unless $state->{not};
$OpenBSD::PackingElement::Lib::todo = 0;
}
our $registered_libs = {};
sub register_lib
{
my ($name, $pkgname) = @_;
my ($stem, $major, $minor, $dir) =
OpenBSD::PackingElement::Lib->parse($name);
if (defined $stem) {
push(@{$registered_libs->{$stem}->{$dir}->{$major}},
[$minor, $pkgname]);
}
}
my $done_plist = {};
sub system_dirs
{
return OpenBSD::Paths->library_dirs;
}
sub add_libs_from_system
{
my ($destdir) = @_;
return if $done_plist->{'system'};
$done_plist->{'system'} = 1;
for my $dirname (system_dirs()) {
opendir(my $dir, $destdir.$dirname."/lib") or next;
while (my $d = readdir($dir)) {
register_lib("$dirname/lib/$d", 'system');
}
closedir($dir);
}
}
sub add_libs_from_installed_package
{
my $pkgname = shift;
return if $done_plist->{$pkgname};
$done_plist->{$pkgname} = 1;
my $plist = OpenBSD::PackingList->from_installation($pkgname,
\&OpenBSD::PackingList::LibraryOnly);
return if !defined $plist;
$plist->mark_available_lib($pkgname);
}
sub add_libs_from_plist
{
my $plist = shift;
my $pkgname = $plist->pkgname;
return if $done_plist->{$pkgname};
$done_plist->{$pkgname} = 1;
$plist->mark_available_lib($pkgname);
}
sub normalize_dir_and_spec
{
my ($base, $libspec) = @_;
if ($libspec =~ m/^(.*)\/([^\/]+)$/o) {
return ("$base/$1", $2);
} else {
return ("$base/lib", $libspec);
}
}
sub parse_spec
{
my $spec = shift;
if ($spec =~ m/^(.*)\.(\d+)\.(\d+)$/o) {
return ($1, $2, $3);
} else {
return undef;
}
}
sub lookup_libspec
{
my ($dir, $spec) = normalize_dir_and_spec(@_);
my @r = ();
my ($libname, $major, $minor) = parse_spec($spec);
if (defined $libname) {
my $exists = $registered_libs->{$libname}->{$dir}->{$major};
if (defined $exists) {
for my $e (@$exists) {
if ($e->[0] >= $minor) {
push(@r, $e->[1]);
}
}
}
}
return @r;
}
sub entry_string
{
my ($stem, $M, $m) = @_;
return "lib$stem.so.$M.$m";
}
sub why_is_this_bad
{
my ($base, $name, $d1, $d2, $M1, $M2, $m1, $m2, $pkgname) = @_;
if ($d1 ne $d2 && !($pkgname eq 'system' && $d1 eq "$base/lib")) {
return "bad directory";
}
if ($M1 != $M2) {
return "bad major";
}
if ($m1 > $m2) {
return "minor not large enough";
}
return "$pkgname not reachable";
}
my $printed = {};
sub report_problem
{
my ($state, $p) = @_;
my $base = $state->{localbase};
my ($dir, $name) = normalize_dir_and_spec($base, $p);
my ($stem, $major, $minor) = parse_spec($name);
return unless defined $stem;
return unless defined $registered_libs->{$stem};
my $r = "";
while (my ($d, $v) = each %{$registered_libs->{$stem}}) {
my @l = ();
while (my ($M, $w) = each %$v) {
for my $e (@$w) {
push(@l, entry_string($stem, $M, $e->[0]).
" (".why_is_this_bad($base, $name, $dir,
$d, $major, $M, $minor, $e->[0], $e->[1]).
")");
}
}
if (@l > 0) {
$r .= "| in $d: ". join(", ", sort @l). "\n";
}
}
if (!defined $printed->{$name} || $printed->{$name} ne $r) {
$printed->{$name} = $r;
$state->errsay("|library $name not found");
$state->print($r);
}
}
1;
|