Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 84 lines 2.8 kB view raw
1From 783ec26c0d83013baf04579a6a415d7f8776ac93 Mon Sep 17 00:00:00 2001 2From: Someone Serge <sergei.kozlukov@aalto.fi> 3Date: Sun, 7 Jan 2024 11:48:24 +0000 4Subject: [PATCH] ldCache(): patch for @driverLink@ 5 6--- 7 internal/pkg/util/paths/resolve.go | 41 +++++++++++++++++++++++++++--- 8 1 file changed, 38 insertions(+), 3 deletions(-) 9 10diff --git a/internal/pkg/util/paths/resolve.go b/internal/pkg/util/paths/resolve.go 11index db45d9db1..9d0110b6b 100644 12--- a/internal/pkg/util/paths/resolve.go 13+++ b/internal/pkg/util/paths/resolve.go 14@@ -14,6 +14,7 @@ import ( 15 "fmt" 16 "os" 17 "os/exec" 18+ "path" 19 "path/filepath" 20 "regexp" 21 "strings" 22@@ -154,14 +155,49 @@ func Resolve(fileList []string) ([]string, []string, error) { 23 // lists three variants of libEGL.so.1 that are in different locations, we only 24 // report the first, highest priority, variant. 25 func ldCache() (map[string]string, error) { 26+ driverDirs := strings.Split("@driverLink@/lib", ":") 27+ if machine, err := elfMachine(); err == nil && machine == elf.EM_386 { 28+ driverDirs = strings.Split("@driverLink@-32/lib", ":") 29+ } 30+ 31+ soPattern, err := regexp.Compile(`[^\s]+\.so(\.\d+(\.\d+(\.\d+)?)?)?$`) 32+ if err != nil { 33+ return nil, fmt.Errorf("could not compile ldconfig regexp: %v", err) 34+ } 35+ 36+ ldCache := make(map[string]string) 37+ for _, dirPath := range driverDirs { 38+ dir, err := os.Open(dirPath) 39+ if err != nil { 40+ /* Maybe we're not running under NixOS */ 41+ continue 42+ } 43+ files, err := dir.ReadDir(-1) 44+ if err != nil { 45+ continue 46+ } 47+ for _, f := range files { 48+ if !soPattern.MatchString(f.Name()) { 49+ continue 50+ } 51+ libName := f.Name() 52+ libPath := path.Join(dirPath, f.Name()) 53+ if _, ok := ldCache[libName]; !ok { 54+ ldCache[libName] = libPath 55+ } 56+ } 57+ } 58+ 59 // walk through the ldconfig output and add entries which contain the filenames 60 // returned by nvidia-container-cli OR the nvliblist.conf file contents 61 ldconfig, err := bin.FindBin("ldconfig") 62- if err != nil { 63+ if err != nil && len(ldCache) == 0 { 64+ // Note that missing ldconfig is only an "error" as long 65+ // as there's no driverLink 66 return nil, err 67 } 68 out, err := exec.Command(ldconfig, "-p").Output() 69- if err != nil { 70+ if err != nil && len(ldCache) == 0 { 71 return nil, fmt.Errorf("could not execute ldconfig: %v", err) 72 } 73 74@@ -173,7 +209,6 @@ func ldCache() (map[string]string, error) { 75 } 76 77 // store library name with associated path 78- ldCache := make(map[string]string) 79 for _, match := range r.FindAllSubmatch(out, -1) { 80 if match != nil { 81 // libName is the "libnvidia-ml.so.1" (from the above example) 82-- 832.42.0 84