Skip to content

Commit bb74690

Browse files
committed
updated pldd.go
1 parent 8529dc6 commit bb74690

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

pldd.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ func main() {
8282
}
8383
defer file.Close()
8484

85-
// Scan through each line of the file
85+
// use a map to dedupe .so libraries
86+
soFiles := make(map[string]bool)
87+
8688
scanner := bufio.NewScanner(file)
8789
for scanner.Scan() {
8890
line := scanner.Text()
89-
90-
// Split the line by spaces to get the different fields
9191
fields := strings.Fields(line)
9292
if len(fields) == 0 {
9393
continue
@@ -100,10 +100,14 @@ func main() {
100100
if strings.HasSuffix(libPath, ".so") || strings.Contains(libPath, ".so.") {
101101
// get the absolute path of the shared library
102102
absPath, err := filepath.EvalSymlinks(libPath)
103-
if err == nil {
103+
if err != nil {
104+
absPath = libPath
105+
}
106+
107+
// dedupe .so against map
108+
if !soFiles[absPath] {
109+
soFiles[absPath] = true
104110
fmt.Println(absPath)
105-
} else {
106-
fmt.Println(libPath)
107111
}
108112
}
109113
}
@@ -118,7 +122,7 @@ func isNumeric(arg string) bool {
118122
return err == nil
119123
}
120124

121-
// Helper function to get the maximum possible PID from /proc/sys/kernel/pid_max
125+
// get the maximum possible PID from /proc/sys/kernel/pid_max
122126
func getMaxPid() (int, error) {
123127
data, err := ioutil.ReadFile("/proc/sys/kernel/pid_max")
124128
if err != nil {

0 commit comments

Comments
 (0)