Implement review suggestions

This commit is contained in:
Daniel
2020-05-19 16:57:55 +02:00
parent 65a3456165
commit e65ae8b55d
14 changed files with 130 additions and 100 deletions

View File

@@ -10,11 +10,9 @@ import (
"sync"
"syscall"
"github.com/safing/portbase/log"
)
"github.com/safing/portmaster/network/socket"
const (
unidentifiedProcessID = -1
"github.com/safing/portbase/log"
)
var (
@@ -23,7 +21,7 @@ var (
)
// FindPID returns the pid of the given uid and socket inode.
func FindPID(uid, inode int) (pid int, ok bool) { //nolint:gocognit // TODO
func FindPID(uid, inode int) (pid int) { //nolint:gocognit // TODO
pidsByUserLock.Lock()
defer pidsByUserLock.Unlock()
@@ -42,7 +40,7 @@ func FindPID(uid, inode int) (pid int, ok bool) { //nolint:gocognit // TODO
var checkedUserPids []int
for _, possiblePID := range pids {
if findSocketFromPid(possiblePID, inode) {
return possiblePID, true
return possiblePID
}
checkedUserPids = append(checkedUserPids, possiblePID)
}
@@ -61,7 +59,7 @@ func FindPID(uid, inode int) (pid int, ok bool) { //nolint:gocognit // TODO
// only check if not already checked
if sort.SearchInts(checkedUserPids, possiblePID) == len {
if findSocketFromPid(possiblePID, inode) {
return possiblePID, true
return possiblePID
}
}
}
@@ -75,13 +73,13 @@ func FindPID(uid, inode int) (pid int, ok bool) { //nolint:gocognit // TODO
if possibleUID != uid {
for _, possiblePID := range pids {
if findSocketFromPid(possiblePID, inode) {
return possiblePID, true
return possiblePID
}
}
}
}
return unidentifiedProcessID, false
return socket.UnidentifiedProcessID
}
func findSocketFromPid(pid, inode int) bool {