mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-25 09:33:24 +01:00
2577100096
replaces PID with checking process name and path and UID checks
27 lines
461 B
Go
27 lines
461 B
Go
//go:build !windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/shirou/gopsutil/v3/process"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func isProcessOwnedByCurrentUser(p *process.Process) bool {
|
|
currentUserID := os.Getuid()
|
|
uids, err := p.Uids()
|
|
if err != nil {
|
|
log.Errorf("get process uids: %v", err)
|
|
return false
|
|
}
|
|
for _, id := range uids {
|
|
log.Debugf("checking process uid: %d", id)
|
|
if int(id) == currentUserID {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|