proxy_linux.go 803 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package portmapper
  2. import (
  3. "net"
  4. "os/exec"
  5. "strconv"
  6. "syscall"
  7. )
  8. func newProxyCommand(proto string, hostIP net.IP, hostPort int, containerIP net.IP, containerPort int, proxyPath string) (userlandProxy, error) {
  9. path := proxyPath
  10. if proxyPath == "" {
  11. cmd, err := exec.LookPath(userlandProxyCommandName)
  12. if err != nil {
  13. return nil, err
  14. }
  15. path = cmd
  16. }
  17. args := []string{
  18. path,
  19. "-proto", proto,
  20. "-host-ip", hostIP.String(),
  21. "-host-port", strconv.Itoa(hostPort),
  22. "-container-ip", containerIP.String(),
  23. "-container-port", strconv.Itoa(containerPort),
  24. }
  25. return &proxyCommand{
  26. cmd: &exec.Cmd{
  27. Path: path,
  28. Args: args,
  29. SysProcAttr: &syscall.SysProcAttr{
  30. Pdeathsig: syscall.SIGTERM, // send a sigterm to the proxy if the daemon process dies
  31. },
  32. },
  33. }, nil
  34. }