github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/kata_proxy.go (about)

     1  // Copyright (c) 2017 Intel Corporation
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  //
     5  
     6  package virtcontainers
     7  
     8  import (
     9  	"os/exec"
    10  	"syscall"
    11  )
    12  
    13  // This is the Kata Containers implementation of the proxy interface.
    14  // This is pretty simple since it provides the same interface to both
    15  // runtime and shim as if they were talking directly to the agent.
    16  type kataProxy struct {
    17  }
    18  
    19  // The kata proxy doesn't need to watch the vm console, thus return false always.
    20  func (p *kataProxy) consoleWatched() bool {
    21  	return false
    22  }
    23  
    24  // start is kataProxy start implementation for proxy interface.
    25  func (p *kataProxy) start(params proxyParams) (int, string, error) {
    26  	if err := validateProxyParams(params); err != nil {
    27  		return -1, "", err
    28  	}
    29  
    30  	params.logger.Debug("Starting regular Kata proxy rather than built-in")
    31  
    32  	// construct the socket path the proxy instance will use
    33  	proxyURL, err := defaultProxyURL(params.id, SocketTypeUNIX)
    34  	if err != nil {
    35  		return -1, "", err
    36  	}
    37  
    38  	args := []string{
    39  		params.path,
    40  		"-listen-socket", proxyURL,
    41  		"-mux-socket", params.agentURL,
    42  		"-sandbox", params.id,
    43  	}
    44  
    45  	if params.debug {
    46  		args = append(args, "-log", "debug", "-agent-logs-socket", params.consoleURL)
    47  	}
    48  
    49  	cmd := exec.Command(args[0], args[1:]...)
    50  	cmd.SysProcAttr = &syscall.SysProcAttr{
    51  		Setsid: true,
    52  	}
    53  	if err := cmd.Start(); err != nil {
    54  		return -1, "", err
    55  	}
    56  
    57  	go cmd.Wait()
    58  
    59  	return cmd.Process.Pid, proxyURL, nil
    60  }
    61  
    62  // stop is kataProxy stop implementation for proxy interface.
    63  func (p *kataProxy) stop(pid int) error {
    64  	// Signal the proxy with SIGTERM.
    65  	return syscall.Kill(pid, syscall.SIGTERM)
    66  }