github.com/sagernet/sing-box@v1.9.0-rc.20/common/process/searcher_linux.go (about)

     1  //go:build linux && !android
     2  
     3  package process
     4  
     5  import (
     6  	"context"
     7  	"net/netip"
     8  
     9  	"github.com/sagernet/sing-box/log"
    10  )
    11  
    12  var _ Searcher = (*linuxSearcher)(nil)
    13  
    14  type linuxSearcher struct {
    15  	logger log.ContextLogger
    16  }
    17  
    18  func NewSearcher(config Config) (Searcher, error) {
    19  	return &linuxSearcher{config.Logger}, nil
    20  }
    21  
    22  func (s *linuxSearcher) FindProcessInfo(ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error) {
    23  	inode, uid, err := resolveSocketByNetlink(network, source, destination)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  	processPath, err := resolveProcessNameByProcSearch(inode, uid)
    28  	if err != nil {
    29  		s.logger.DebugContext(ctx, "find process path: ", err)
    30  	}
    31  	return &Info{
    32  		UserId:      int32(uid),
    33  		ProcessPath: processPath,
    34  	}, nil
    35  }