mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-19 17:50:12 +00:00
fix(agentcompat): root proc resource reads
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
@@ -15,8 +15,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func readRSSBytes(pid int) (uint64, error) {
|
func readRSSBytes(pid int) (uint64, error) {
|
||||||
path := filepath.Join("/proc", strconv.Itoa(pid), "status")
|
path := filepath.Join(strconv.Itoa(pid), "status")
|
||||||
file, err := os.Open(path)
|
procRoot, err := os.OpenRoot("/proc")
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer procRoot.Close()
|
||||||
|
file, err := procRoot.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@@ -73,8 +78,13 @@ func descendantPIDs(rootPID int) ([]int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readParentPID(pid int) (int, error) {
|
func readParentPID(pid int) (int, error) {
|
||||||
path := filepath.Join("/proc", strconv.Itoa(pid), "stat")
|
path := filepath.Join(strconv.Itoa(pid), "stat")
|
||||||
data, err := os.ReadFile(path)
|
procRoot, err := os.OpenRoot("/proc")
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer procRoot.Close()
|
||||||
|
data, err := procRoot.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@@ -130,8 +140,16 @@ func parseSocketInode(target string) (uint64, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func listeningSocketInodes(pid int, protocol string) (map[uint64]struct{}, error) {
|
func listeningSocketInodes(pid int, protocol string) (map[uint64]struct{}, error) {
|
||||||
path := filepath.Join("/proc", strconv.Itoa(pid), "net", protocol)
|
if protocol != "tcp" && protocol != "tcp6" {
|
||||||
file, err := os.Open(path)
|
return nil, errors.New("unsupported proc network protocol")
|
||||||
|
}
|
||||||
|
path := filepath.Join(strconv.Itoa(pid), "net", protocol)
|
||||||
|
procRoot, err := os.OpenRoot("/proc")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer procRoot.Close()
|
||||||
|
file, err := procRoot.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,10 +67,15 @@ func socketInode(file *os.File) (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func listenerInodePresent(inode uint64) (bool, error) {
|
func listenerInodePresent(inode uint64) (bool, error) {
|
||||||
for _, path := range []string{"/proc/self/net/tcp", "/proc/self/net/tcp6"} {
|
procNet, err := os.OpenRoot("/proc/self/net")
|
||||||
file, err := os.Open(path)
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("open listener tables: %w", err)
|
||||||
|
}
|
||||||
|
defer procNet.Close()
|
||||||
|
for _, name := range []string{"tcp", "tcp6"} {
|
||||||
|
file, err := procNet.Open(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("open listener table %s: %w", path, err)
|
return false, fmt.Errorf("open listener table %s: %w", name, err)
|
||||||
}
|
}
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
|||||||
Reference in New Issue
Block a user