searcher_with_name.go 553 B

12345678910111213141516171819202122232425
  1. //go:build linux && !android
  2. package process
  3. import (
  4. "context"
  5. "net/netip"
  6. "os/user"
  7. F "github.com/sagernet/sing/common/format"
  8. )
  9. func findProcessInfo(searcher Searcher, ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error) {
  10. info, err := searcher.FindProcessInfo(ctx, network, source, destination)
  11. if err != nil {
  12. return nil, err
  13. }
  14. if info.UserId != -1 {
  15. osUser, _ := user.LookupId(F.ToString(info.UserId))
  16. if osUser != nil {
  17. info.User = osUser.Username
  18. }
  19. }
  20. return info, nil
  21. }