Documentation ¶
Overview ¶
Package envexec provides utility function to run program in restricted environments through container and cgroup.
Cmd ¶
Cmd defines single program to run, including copyin files before exec, run the program and copy out files after exec
Single ¶
Single defines single Cmd with Environment and Cgroup Pool ¶
Group ¶
Group defines multiple Cmd with Environment and Cgroup Pool, together with Pipe mapping between different Cmd
Index ¶
- func FileToReader(f File) (io.ReadCloser, error)
- type Cmd
- type Environment
- type ExecveParam
- type File
- type FileInput
- type FileOpened
- type FilePipeCollector
- type FileReader
- type FileWriter
- type Group
- type Limit
- type Pipe
- type PipeIndex
- type Process
- type ReaderTTY
- type Result
- type RunnerResult
- type Single
- type Size
- type Status
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileToReader ¶ added in v1.1.0
func FileToReader(f File) (io.ReadCloser, error)
FileToReader get a ReadCloser from underlying file
Types ¶
type Cmd ¶
type Cmd struct { Environment Environment // file contents to copyin before exec CopyIn map[string]File // exec argument, environment Args []string Env []string // Files for the executing command Files []File TTY bool // use pty as input / output // resource limits TimeLimit time.Duration MemoryLimit Size StackLimit Size ExtraMemoryLimit Size OutputLimit Size ProcLimit uint64 CPURateLimit float64 StrictMemoryLimit bool // Waiter is called after cmd starts and it should return // once time limit exceeded. // return true to as TLE and false as normal exits (context finished) Waiter func(context.Context, Process) bool // file names to copyout after exec CopyOut []string CopyOutMax Size // file size limit // CopyOutDir specifies a dir to dump all /w contnet CopyOutDir string }
Cmd defines instruction to run a program in container environment
type Environment ¶
type Environment interface { Execve(context.Context, ExecveParam) (Process, error) WorkDir() *os.File // WorkDir returns opened work directory, should not close after // Open open file at work dir with given relative path and flags Open(path string, flags int, perm os.FileMode) (*os.File, error) }
Environment defines the interface to access container execution environment
type ExecveParam ¶
type ExecveParam struct { // Args holds command line arguments Args []string // Env specifies the environment of the process Env []string // Files specifies file descriptors for the child process Files []uintptr // ExecFile specifies file descriptor for executable file using fexecve ExecFile uintptr // TTY specifies whether to use TTY TTY bool // Process Limitations Limit Limit }
ExecveParam is parameters to run process inside environment
type File ¶ added in v1.1.0
type File interface {
// contains filtered or unexported methods
}
File defines interface of envexec files
func NewFileInput ¶ added in v1.1.0
NewFileInput creates file input which will be opened in read-only mode
func NewFileOpened ¶ added in v1.1.0
NewFileOpened creates file that contains already opened file and it will be closed
func NewFilePipeCollector ¶ added in v1.1.0
NewFilePipeCollector creates file output which will be collected through pipe
func NewFileReader ¶ added in v1.1.0
NewFileReader creates File input which can be fully read before exec or piped into exec
type FileInput ¶ added in v1.1.0
type FileInput struct {
Path string
}
FileInput represent file input which will be opened in read-only mode
type FileOpened ¶ added in v1.1.0
FileOpened represent file that is already opened
type FilePipeCollector ¶ added in v1.1.0
FilePipeCollector represent pipe output which will be collected through pipe
type FileReader ¶ added in v1.1.0
FileReader represent file input which can be fully read before exec or piped into exec
type FileWriter ¶ added in v1.1.0
FileWriter represent pipe output which will be piped out from exec
type Group ¶
type Group struct { // Cmd defines Cmd running in parallel in multiple environments Cmd []*Cmd // Pipes defines the potential mapping between Cmd. // ensure nil is used as placeholder in correspond cmd Pipes []*Pipe }
Group defines the running instruction to run multiple exec in parallel restricted within cgroup
type Limit ¶
type Limit struct { Time time.Duration // Time limit Memory Size // Memory limit Proc uint64 // Process count limit Stack Size // Stack limit Output Size // Output limit Rate float64 // CPU Rate limit StrictMemory bool // Use stricter memory limit (e.g. rlimit) }
Limit defines the process running resource limits
type Process ¶
type Process interface { Done() <-chan struct{} // Done returns a channel for wait process to exit Result() RunnerResult // Result wait until done and returns RunnerResult Usage() Usage // Usage retrieves the process usage during the run time }
Process reference to the running process group
type ReaderTTY ¶ added in v1.1.0
ReaderTTY will be asserts when File Reader is provided and TTY is enabled and then TTY will be called with pty file
type Result ¶
type Result struct { Status Status ExitStatus int Error string // error Time time.Duration RunTime time.Duration Memory Size // byte // Files stores copy out files Files map[string][]byte }
Result defines the running result for single Cmd
type Single ¶
type Single struct { // Cmd defines Cmd running in parallel in multiple environments Cmd *Cmd }
Single defines the running instruction to run single exec in restricted within cgroup
type Status ¶
type Status int
Status defines run task Status return status
const ( // not initialized status (as error) StatusInvalid Status = iota // exit normally StatusAccepted StatusWrongAnswer StatusPartiallyCorrect // exit with error StatusMemoryLimitExceeded // MLE StatusTimeLimitExceeded // TLE StatusOutputLimitExceeded // OLE StatusFileError // FE StatusNonzeroExitStatus // NZS StatusSignalled // SIG StatusDangerousSyscall // DJS // SPJ / interactor error StatusJudgementFailed StatusInvalidInteraction // interactor signals error // internal error including: cgroup init failed, container failed, etc StatusInternalError )
Defines run task Status result status
func StringToStatus ¶ added in v1.1.7
Convert string to Status