Skip to content

Commit

Permalink
linuxcontainer: bump dependency versions go1.16.5
Browse files Browse the repository at this point in the history
  • Loading branch information
criyle committed Jun 6, 2021
1 parent 9dba0d0 commit 46ec099
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 67 deletions.
24 changes: 21 additions & 3 deletions env/linuxcontainer/environment_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/criyle/go-sandbox/container"
"github.com/criyle/go-sandbox/pkg/cgroup"
"github.com/criyle/go-sandbox/pkg/rlimit"
"github.com/criyle/go-sandbox/runner"
)

var _ envexec.Environment = &environ{}
Expand Down Expand Up @@ -65,6 +66,9 @@ func (c *environ) Execve(ctx context.Context, param envexec.ExecveParam) (envexe
rLimits.Data = limit.Memory.Byte()
}

// wait for sync or error before turn (avoid file close before pass to child process)
syncDone := make(chan struct{})

p := container.ExecveParam{
Args: param.Args,
Env: param.Env,
Expand All @@ -73,10 +77,24 @@ func (c *environ) Execve(ctx context.Context, param envexec.ExecveParam) (envexe
ExecFile: param.ExecFile,
RLimits: rLimits.PrepareRLimit(),
Seccomp: c.seccomp,
SyncFunc: syncFunc,
SyncFunc: func(pid int) error {
defer close(syncDone)
if syncFunc != nil {
return syncFunc(pid)
}
return nil
},
}
proc := newProcess(func() runner.Result {
return c.Environment.Execve(ctx, p)
}, cg, c.cgPool)

select {
case <-proc.done:
case <-syncDone:
}
rt := c.Environment.Execve(ctx, p)
return newProcess(rt, cg, c.cgPool), nil

return proc, nil
}

// WorkDir returns opened work directory, should not close after
Expand Down
25 changes: 15 additions & 10 deletions env/linuxcontainer/envprocess_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type process struct {
cg Cgroup
}

func newProcess(ch <-chan runner.Result, cg Cgroup, cgPool CgroupPool) *process {
func newProcess(run func() runner.Result, cg Cgroup, cgPool CgroupPool) *process {
p := &process{
done: make(chan struct{}),
cg: cg,
Expand All @@ -26,19 +26,24 @@ func newProcess(ch <-chan runner.Result, cg Cgroup, cgPool CgroupPool) *process
if cgPool != nil {
defer cgPool.Put(cg)
}
p.rt = <-ch
if cg != nil {
if t, err := cg.CPUUsage(); err == nil {
p.rt.Time = t
}
if m, err := cg.MemoryUsage(); err == nil {
p.rt.Memory = m
}
}
p.rt = run()
p.collectUsage()
}()
return p
}

func (p *process) collectUsage() {
if p.cg == nil {
return
}
if t, err := p.cg.CPUUsage(); err == nil {
p.rt.Time = t
}
if m, err := p.cg.MemoryUsage(); err == nil {
p.rt.Memory = m
}
}

func (p *process) Done() <-chan struct{} {
return p.done
}
Expand Down
30 changes: 14 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module github.com/criyle/go-judge
go 1.16

require (
cloud.google.com/go v0.81.0 // indirect
github.com/creack/pty v1.1.11
github.com/criyle/go-sandbox v0.7.3
cloud.google.com/go v0.83.0 // indirect
github.com/creack/pty v1.1.13
github.com/criyle/go-sandbox v0.7.4
github.com/elastic/go-seccomp-bpf v1.1.0
github.com/elastic/go-ucfg v0.8.3
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/gin-contrib/pprof v1.3.0
github.com/gin-contrib/zap v0.0.1
github.com/gin-gonic/gin v1.7.1
github.com/go-playground/validator/v10 v10.6.0 // indirect
github.com/gin-gonic/gin v1.7.2
github.com/go-playground/validator/v10 v10.6.1 // indirect
github.com/golang/protobuf v1.5.2
github.com/gorilla/websocket v1.4.2
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
Expand All @@ -22,26 +22,24 @@ require (
github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/prometheus/client_golang v1.10.0
github.com/prometheus/common v0.23.0 // indirect
github.com/prometheus/common v0.27.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/ugorji/go v1.2.5 // indirect
github.com/ugorji/go v1.2.6 // indirect
github.com/zsais/go-gin-prometheus v0.1.0
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210508051633-16afe75a6701
golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c // indirect
go.uber.org/zap v1.17.0
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
golang.org/x/net v0.0.0-20210525063256-abc453219eb5
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096
golang.org/x/sys v0.0.0-20210603125802-9665404d3644
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
google.golang.org/genproto v0.0.0-20210506142907-4a47615972c2 // indirect
google.golang.org/grpc v1.37.0
google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08 // indirect
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.26.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0
honnef.co/go/tools v0.1.4 // indirect
)

retract (
Expand Down
Loading

0 comments on commit 46ec099

Please sign in to comment.