diff options
| author | Taras Madan <tarasmadan@google.com> | 2025-05-15 15:01:02 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2025-05-19 09:39:47 +0000 |
| commit | 27f689959decd391b047c8034d481267d500549e (patch) | |
| tree | 79ce6364d592fd6841e25ec64ca645fc3c65cdcf /vm/vmm | |
| parent | 8f9cf946b3733d0b4ad3124bce155a4fc3849c3a (diff) | |
vm: func Run accepts context
It allows to use context as a single termination signal source.
Diffstat (limited to 'vm/vmm')
| -rw-r--r-- | vm/vmm/vmm.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/vm/vmm/vmm.go b/vm/vmm/vmm.go index 35fdf7650..5190e32b3 100644 --- a/vm/vmm/vmm.go +++ b/vm/vmm/vmm.go @@ -5,6 +5,7 @@ package vmm import ( + "context" "fmt" "io" "os" @@ -250,7 +251,7 @@ func (inst *instance) Copy(hostSrc string) (string, error) { return vmDst, 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) { rpipe, wpipe, err := osutil.LongPipe() if err != nil { @@ -281,9 +282,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() |
