Просмотр исходного кода

Feature #TASK_QT-18250 状态控制bug

Carl 1 месяц назад
Родитель
Сommit
490749dce3
3 измененных файлов с 13 добавлено и 1 удалено
  1. 1 0
      containers/container.go
  2. 4 0
      utils/modelse/app_info.go
  3. 8 1
      utils/util.go

+ 1 - 0
containers/container.go

@@ -1460,6 +1460,7 @@ func (c *Container) AttachUprobes(tracer *ebpftracer.Tracer, pid uint32, _type s
 		return fmt.Errorf("[attach] Not Supported codeType: %s", codeType.String())
 	}
 	if err != nil {
+		c.AppInfo.SetAppUprobeError()
 		klog.WithField("pid", pid).Errorf("[attach] error  %v :", err)
 		deErr := c.DetachUprobes(tracer, pid, APP_UPROBE_ERROR)
 		if deErr != nil {

+ 4 - 0
utils/modelse/app_info.go

@@ -120,6 +120,10 @@ func (a *AppInfo) SetAppStackError() {
 	a.SetAppStatus(APP_STACK_ERROR)
 }
 
+func (a *AppInfo) SetAppUprobeError() {
+	a.SetAppStatus(APP_UPROBE_ERROR)
+}
+
 func (a *AppInfo) AppUninstall() {
 	a.SetAppStatus(APP_UNINSTALL)
 }

+ 8 - 1
utils/util.go

@@ -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
 				}
 			}
 		}