aboutsummaryrefslogtreecommitdiffstats
path: root/vm/gvisor
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2025-05-15 15:01:02 +0200
committerTaras Madan <tarasmadan@google.com>2025-05-19 09:39:47 +0000
commit27f689959decd391b047c8034d481267d500549e (patch)
tree79ce6364d592fd6841e25ec64ca645fc3c65cdcf /vm/gvisor
parent8f9cf946b3733d0b4ad3124bce155a4fc3849c3a (diff)
vm: func Run accepts context
It allows to use context as a single termination signal source.
Diffstat (limited to 'vm/gvisor')
-rw-r--r--vm/gvisor/gvisor.go7
1 files changed, 3 insertions, 4 deletions
diff --git a/vm/gvisor/gvisor.go b/vm/gvisor/gvisor.go
index 8336ee450..b62dcb790 100644
--- a/vm/gvisor/gvisor.go
+++ b/vm/gvisor/gvisor.go
@@ -7,6 +7,7 @@ package gvisor
import (
"bytes"
+ "context"
"fmt"
"io"
"net"
@@ -286,7 +287,7 @@ func (inst *instance) Copy(hostSrc string) (string, error) {
return filepath.Join("/", fname), nil
}
-func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command string) (
+func (inst *instance) Run(ctx context.Context, command string) (
<-chan []byte, <-chan error, error) {
args := []string{"exec", "-user=0:0"}
for _, c := range sandboxCaps {
@@ -327,9 +328,7 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin
go func() {
select {
- case <-time.After(timeout):
- signal(vmimpl.ErrTimeout)
- case <-stop:
+ case <-ctx.Done():
signal(vmimpl.ErrTimeout)
case err := <-inst.merger.Err:
cmd.Process.Kill()