From 27f689959decd391b047c8034d481267d500549e Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Thu, 15 May 2025 15:01:02 +0200 Subject: vm: func Run accepts context It allows to use context as a single termination signal source. --- vm/gvisor/gvisor.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'vm/gvisor') 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() -- cgit mrf-deployment