mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 19:00:50 +01:00
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
|
||
|
}
|