|
|
@@ -928,6 +928,13 @@ func ToString(v interface{}) string {
|
|
|
}
|
|
|
|
|
|
func GetSoPath(pid uint32, soname string, rootfs string) (string, error) {
|
|
|
+ // 容器进程的 so 文件无法通过裸路径访问,需加上根文件系统前缀。
|
|
|
+ // 若调用方未提供 rootfs(metadata 不可用),fallback 到 /proc/<pid>/root,
|
|
|
+ // 该路径在宿主机上始终可达,对宿主机进程同样无害(/proc/1/root == /)。
|
|
|
+ effectiveRootfs := rootfs
|
|
|
+ if effectiveRootfs == "" {
|
|
|
+ effectiveRootfs = fmt.Sprintf("/proc/%d/root", pid)
|
|
|
+ }
|
|
|
mapsFile := fmt.Sprintf("/proc/%d/maps", pid)
|
|
|
file, err := os.Open(mapsFile)
|
|
|
if err != nil {
|
|
|
@@ -942,7 +949,7 @@ func GetSoPath(pid uint32, soname string, rootfs string) (string, error) {
|
|
|
if len(fields) > 5 {
|
|
|
path := fields[5]
|
|
|
if strings.HasSuffix(path, ".so") {
|
|
|
- return filepath.Join(rootfs, path), nil
|
|
|
+ return filepath.Join(effectiveRootfs, path), nil
|
|
|
}
|
|
|
}
|
|
|
}
|