Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit c7f4339

Browse files
authored
Merge pull request #20 from oracle/deps
Better path searching for deps
2 parents a7e00b9 + 1dbaacc commit c7f4339

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

build.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func buildMock(buildOpts *buildOptions, outputDir string, pkg *ConfigDef, pkgMfs
305305
return MockExecuteQuiet(pkg.Mock.Config, name, arg...)
306306
}
307307

308-
if err := SetSoPathsFromExecutor(executor); err != nil {
308+
if err := SetSoPathsFromExecutor(executor, nil); err != nil {
309309
return err
310310
}
311311

@@ -358,10 +358,14 @@ func buildOci(buildOpts *buildOptions, outputDir string, pkg *ConfigDef) error {
358358

359359
// set path for executor
360360
path := "/usr/sbin:/usr/bin:/sbin:/bin"
361+
ld_library_path := ""
361362
for _, e := range pkg.Env {
362363
if strings.HasPrefix(e, "PATH=") {
363364
path = e[len("PATH="):]
364365
}
366+
if strings.HasPrefix(e, "LD_LIBRARY_PATH=") {
367+
ld_library_path = e[len("LD_LIBRARY_PATH="):]
368+
}
365369
}
366370
executor := func(name string, arg ...string) (string, string, error) {
367371
attr := &syscall.SysProcAttr{
@@ -409,7 +413,8 @@ func buildOci(buildOpts *buildOptions, outputDir string, pkg *ConfigDef) error {
409413
}
410414
}
411415

412-
if err := SetSoPathsFromExecutor(executor); err != nil {
416+
preload := strings.Split(ld_library_path, ":")
417+
if err := SetSoPathsFromExecutor(executor, preload); err != nil {
413418
return err
414419
}
415420

deps.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
)
1111

1212
var (
13-
soMap map[string]string
13+
soMap map[string]string
14+
preloadPaths []string
1415
)
1516

1617
type executor func(name string, arg ...string) (string, string, error)
@@ -19,21 +20,22 @@ type executor func(name string, arg ...string) (string, string, error)
1920
// the executor should be a function which takes string args and returns
2021
// stdout, stderr, error. The executor is responsible for setting up the
2122
// proper environment for ldconfig, by chrooting for example.
22-
func SetSoPathsFromExecutor(ex executor) error {
23+
func SetSoPathsFromExecutor(ex executor, preload []string) error {
2324
stdout, stderr, err := ex("ldconfig", "-v", "-N", "-X", "/")
2425
if err != nil {
2526
logrus.Warnf("ldconfig failed: %v", strings.TrimSpace(stderr))
2627
return nil
2728
}
28-
SetSoPaths(stdout)
29+
SetSoPaths(stdout, preload)
2930
return nil
3031
}
3132

3233
// SetSoPaths parses a string formatted like the output from
3334
// ldconfig -v -N -X and stores the so paths for later use by Deps
34-
func SetSoPaths(ldconfigout string) {
35+
func SetSoPaths(ldconfigout string, preload []string) {
3536
lines := strings.Split(ldconfigout, "\n")
3637
soMap = map[string]string{}
38+
preloadPaths = preload
3739
path := ""
3840
for _, line := range lines {
3941
if len(line) == 0 {
@@ -54,7 +56,9 @@ func SetSoPaths(ldconfigout string) {
5456
// we use the source name for the mapping because we want to
5557
// keep the symlink around for the loader
5658
source := strings.TrimSpace(parts[0])
57-
soMap[source] = filepath.Join(path, source)
59+
if _, ok := soMap[source]; !ok {
60+
soMap[source] = filepath.Join(path, source)
61+
}
5862
}
5963
}
6064
}
@@ -103,7 +107,7 @@ func Deps(chrootDir, path string, nss bool) (map[string]struct{}, error) {
103107
if err != nil || needs == nil {
104108
return result, nil
105109
}
106-
paths := []string{}
110+
paths := preloadPaths
107111
runpaths, err := elfFile.DynString(elf.DT_RUNPATH)
108112
shortPath := strings.TrimPrefix(path, chrootDir)
109113
origin := filepath.Dir(shortPath)

deps_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestDeps(t *testing.T) {
3535
expected[dep] = struct{}{}
3636
}
3737

38-
err := SetSoPathsFromExecutor(execute.ExecuteQuiet)
38+
err := SetSoPathsFromExecutor(execute.ExecuteQuiet, nil)
3939
if err != nil {
4040
t.Fatalf("%v", err)
4141
}
@@ -55,7 +55,7 @@ func TestDepsNss(t *testing.T) {
5555
expected[dep] = struct{}{}
5656
}
5757

58-
err := SetSoPathsFromExecutor(execute.ExecuteQuiet)
58+
err := SetSoPathsFromExecutor(execute.ExecuteQuiet, nil)
5959
if err != nil {
6060
t.Fatalf("%v", err)
6161
}
@@ -76,7 +76,7 @@ func TestFindLibrary(t *testing.T) {
7676
exec := func(name string, arg ...string) (string, string, error) {
7777
return fakeLdconfig, "", nil
7878
}
79-
err := SetSoPathsFromExecutor(exec)
79+
err := SetSoPathsFromExecutor(exec, nil)
8080
if err != nil {
8181
t.Fatalf("%v", err)
8282
}
@@ -92,7 +92,7 @@ func TestFindLibrarySearch(t *testing.T) {
9292
exec := func(name string, arg ...string) (string, string, error) {
9393
return "", "", nil
9494
}
95-
err := SetSoPathsFromExecutor(exec)
95+
err := SetSoPathsFromExecutor(exec, nil)
9696
if err != nil {
9797
t.Fatalf("%v", err)
9898
}

0 commit comments

Comments
 (0)