mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
add environment setting to language
This commit is contained in:
parent
e0d9c13de4
commit
2903d42e1d
2
go.mod
2
go.mod
@ -2,4 +2,4 @@ module github.com/criyle/go-judge
|
||||
|
||||
go 1.13
|
||||
|
||||
require github.com/criyle/go-sandbox v0.0.0-20191014070058-6e46a732897f
|
||||
require github.com/criyle/go-sandbox v0.0.0-20191016053250-f2a28034f310
|
||||
|
||||
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
||||
github.com/criyle/go-sandbox v0.0.0-20191014070058-6e46a732897f h1:5PNJaA2V/NVR98BegmbYW2g5pHdiX3b1iXdaV/fPA9M=
|
||||
github.com/criyle/go-sandbox v0.0.0-20191014070058-6e46a732897f/go.mod h1:q6ywqlRA0V2VxWo9E+dQkzK2s5mHyq2GXHtF8oZq+mI=
|
||||
github.com/criyle/go-sandbox v0.0.0-20191016053250-f2a28034f310 h1:mE+H7/ycELStwFvM4+1hPUhILrf5lC4WbdiyT8RlD5M=
|
||||
github.com/criyle/go-sandbox v0.0.0-20191016053250-f2a28034f310/go.mod h1:q6ywqlRA0V2VxWo9E+dQkzK2s5mHyq2GXHtF8oZq+mI=
|
||||
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
|
||||
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
|
||||
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
||||
@ -17,6 +17,7 @@ type Language interface {
|
||||
// ExecParam defines specs to compile / run program
|
||||
type ExecParam struct {
|
||||
Args []string
|
||||
Env []string
|
||||
|
||||
// Compile
|
||||
SourceFileName string // put code when compile
|
||||
|
||||
@ -21,10 +21,6 @@ const cgroupPrefix = "go-judge"
|
||||
const minCPUPercent = 40 // 40%
|
||||
const checkIntervalMS = 50
|
||||
|
||||
var env = []string{
|
||||
"PATH=/usr/local/bin:/usr/bin:/bin",
|
||||
}
|
||||
|
||||
func (r *Runner) run(done <-chan struct{}, task *types.RunTask) *types.RunTaskResult {
|
||||
t := language.TypeExec
|
||||
if task.Type == "compile" {
|
||||
@ -35,33 +31,33 @@ func (r *Runner) run(done <-chan struct{}, task *types.RunTask) *types.RunTaskRe
|
||||
// init input / output / error files
|
||||
inputFile, err := task.InputFile.Open()
|
||||
if err != nil {
|
||||
return errResult("failed to initialize input file")
|
||||
return errResult("initialize input file" + err.Error())
|
||||
}
|
||||
defer inputFile.Close()
|
||||
|
||||
outputPipe, err := pipe.NewBuffer(maxOutput)
|
||||
if err != nil {
|
||||
return errResult("failed to initialize output pipe")
|
||||
return errResult("initialize output pipe" + err.Error())
|
||||
}
|
||||
defer outputPipe.W.Close()
|
||||
|
||||
errorPipe, err := pipe.NewBuffer(maxOutput)
|
||||
if err != nil {
|
||||
return errResult("failed to initialize output pipe")
|
||||
return errResult("initialize output pipe: " + err.Error())
|
||||
}
|
||||
defer errorPipe.W.Close()
|
||||
|
||||
// init cgroup
|
||||
cg, err := cgroup.NewCGroup(cgroupPrefix)
|
||||
if err != nil {
|
||||
return errResult("failed to initialize cgroup")
|
||||
return errResult("initialize cgroup: " + err.Error())
|
||||
}
|
||||
defer cg.Destroy()
|
||||
|
||||
// get daemon runner
|
||||
m, err := r.pool.Get()
|
||||
if err != nil {
|
||||
return errResult("failed to get daemon instance")
|
||||
return errResult("get daemon instance: " + err.Error())
|
||||
}
|
||||
defer r.pool.Put(m)
|
||||
|
||||
@ -77,7 +73,7 @@ func (r *Runner) run(done <-chan struct{}, task *types.RunTask) *types.RunTaskRe
|
||||
// set running parameters
|
||||
execParam := daemon.ExecveParam{
|
||||
Args: param.Args,
|
||||
Env: env,
|
||||
Env: param.Env,
|
||||
Fds: []uintptr{inputFile.Fd(), outputPipe.W.Fd(), errorPipe.W.Fd()},
|
||||
SyncFunc: cg.AddProc,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user