2022-08-20 02:38:12 +00:00
|
|
|
//go:build linux && !android
|
2022-07-23 11:01:41 +00:00
|
|
|
|
|
|
|
package process
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/netip"
|
|
|
|
"os/user"
|
|
|
|
|
|
|
|
F "github.com/sagernet/sing/common/format"
|
|
|
|
)
|
|
|
|
|
2022-08-20 02:38:12 +00:00
|
|
|
func findProcessInfo(searcher Searcher, ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error) {
|
|
|
|
info, err := searcher.FindProcessInfo(ctx, network, source, destination)
|
2022-07-23 11:01:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if info.UserId != -1 {
|
|
|
|
osUser, _ := user.LookupId(F.ToString(info.UserId))
|
|
|
|
if osUser != nil {
|
|
|
|
info.User = osUser.Username
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return info, nil
|
|
|
|
}
|