|
|
|
@ -77,7 +77,7 @@ func inodesFromPid(pid int) []uint64 {
|
|
|
|
|
for _, n := range readdir(fdpath) {
|
|
|
|
|
if link, err := os.Readlink(path.Join(fdpath, n)); err != nil {
|
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
|
log.Warning("Error reading link %s: %v", n, err)
|
|
|
|
|
log.Warningf("Error reading link %s: %v", n, err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if inode := extractSocket(link); inode > 0 {
|
|
|
|
@ -95,7 +95,7 @@ func extractSocket(name string) uint64 {
|
|
|
|
|
val := name[8 : len(name)-1]
|
|
|
|
|
inode, err := strconv.ParseUint(val, 10, 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warning("Error parsing inode value from %s: %v", name, err)
|
|
|
|
|
log.Warningf("Error parsing inode value from %s: %v", name, err)
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
return inode
|
|
|
|
@ -104,13 +104,13 @@ func extractSocket(name string) uint64 {
|
|
|
|
|
func readdir(dir string) []string {
|
|
|
|
|
d, err := os.Open(dir)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warning("Error opening directory %s: %v", dir, err)
|
|
|
|
|
log.Warningf("Error opening directory %s: %v", dir, err)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
defer d.Close()
|
|
|
|
|
names, err := d.Readdirnames(0)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warning("Error reading directory names from %s: %v", dir, err)
|
|
|
|
|
log.Warningf("Error reading directory names from %s: %v", dir, err)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return names
|
|
|
|
@ -123,12 +123,12 @@ func (pi *Info) loadProcessInfo() bool {
|
|
|
|
|
|
|
|
|
|
exePath, err := os.Readlink(fmt.Sprintf("/proc/%d/exe", pi.Pid))
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warning("Error reading exe link for pid %d: %v", pi.Pid, err)
|
|
|
|
|
log.Warningf("Error reading exe link for pid %d: %v", pi.Pid, err)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
bs, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pi.Pid))
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warning("Error reading cmdline for pid %d: %v", pi.Pid, err)
|
|
|
|
|
log.Warningf("Error reading cmdline for pid %d: %v", pi.Pid, err)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
for i, b := range bs {
|
|
|
|
@ -139,18 +139,18 @@ func (pi *Info) loadProcessInfo() bool {
|
|
|
|
|
|
|
|
|
|
bs, err = ioutil.ReadFile(fmt.Sprintf("/proc/%d/stat", pi.Pid))
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warning("Error reading cmdline for pid %d: %v", pi.Pid, err)
|
|
|
|
|
log.Warningf("Error reading cmdline for pid %d: %v", pi.Pid, err)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
fs := strings.Fields(string(bs))
|
|
|
|
|
if len(fs) < 50 {
|
|
|
|
|
log.Warning("Unable to parse stat for pid %d: ", pi.Pid)
|
|
|
|
|
log.Warningf("Unable to parse stat for pid %d: ", pi.Pid)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
finfo, err := os.Stat(fmt.Sprintf("/proc/%d", pi.Pid))
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warning("Could not stat /proc/%d: %v", pi.Pid, err)
|
|
|
|
|
log.Warningf("Could not stat /proc/%d: %v", pi.Pid, err)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
sys := finfo.Sys().(*syscall.Stat_t)
|
|
|
|
|