github.com/criyle/go-sandbox@v0.10.3/container/protocol_linux.go (about)

     1  package container
     2  
     3  import (
     4  	"os"
     5  	"syscall"
     6  	"time"
     7  
     8  	"github.com/criyle/go-sandbox/pkg/mount"
     9  	"github.com/criyle/go-sandbox/pkg/rlimit"
    10  	"github.com/criyle/go-sandbox/pkg/seccomp"
    11  	"github.com/criyle/go-sandbox/runner"
    12  )
    13  
    14  // cmd is the control message send into container
    15  type cmd struct {
    16  	DeleteCmd *deleteCmd // delete argument
    17  	ExecCmd   *execCmd   // execve argument
    18  	ConfCmd   *confCmd   // to set configuration
    19  
    20  	OpenCmd []OpenCmd // open argument
    21  
    22  	Cmd cmdType // type of the cmd
    23  }
    24  
    25  // OpenCmd correspond to a single open syscall
    26  type OpenCmd struct {
    27  	Path string
    28  	Flag int
    29  	Perm os.FileMode
    30  }
    31  
    32  // deleteCmd stores delete command
    33  type deleteCmd struct {
    34  	Path string
    35  }
    36  
    37  // execCmd stores execve parameter
    38  type execCmd struct {
    39  	Argv    []string        // execve argv
    40  	Env     []string        // execve env
    41  	RLimits []rlimit.RLimit // execve posix rlimit
    42  	Seccomp seccomp.Filter  // seccomp filter
    43  	FdExec  bool            // if use fexecve (fd[0] as exec)
    44  	CTTY    bool            // if set CTTY
    45  }
    46  
    47  // confCmd stores conf parameter
    48  type confCmd struct {
    49  	Conf containerConfig
    50  }
    51  
    52  // ContainerConfig set the container config
    53  type containerConfig struct {
    54  	WorkDir string
    55  
    56  	HostName   string
    57  	DomainName string
    58  
    59  	ContainerRoot string
    60  	Mounts        []mount.Mount
    61  	SymbolicLinks []SymbolicLink
    62  	MaskPaths     []string
    63  	InitCommand   []string
    64  
    65  	ContainerUID  int
    66  	ContainerGID  int
    67  	Cred          bool
    68  	UnshareCgroup bool
    69  }
    70  
    71  // reply is the reply message send back to controller
    72  type reply struct {
    73  	Error     *errorReply // nil if no error
    74  	ExecReply *execReply
    75  }
    76  
    77  // errorReply stores error returned back from container
    78  type errorReply struct {
    79  	Errno *syscall.Errno
    80  	Msg   string
    81  }
    82  
    83  // execReply stores execve result
    84  type execReply struct {
    85  	ExitStatus int           // waitpid exit status
    86  	Status     runner.Status // return status
    87  	Time       time.Duration // waitpid user CPU (ns)
    88  	Memory     runner.Size   // waitpid user memory (byte)
    89  }
    90  
    91  func (e *errorReply) Error() string {
    92  	return e.Msg
    93  }