Skip to content

Commit 646fde0

Browse files
committed
Add context parameter to the WSL2 status check
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 1ad5804 commit 646fde0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pkg/driver/wsl2/vm_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func provisionVM(ctx context.Context, instanceDir, instanceName, distroName stri
135135
for {
136136
<-ctx.Done()
137137
logrus.Info("Context closed, stopping vm")
138-
if status, err := getWslStatus(instanceName); err == nil &&
138+
if status, err := getWslStatus(ctx, instanceName); err == nil &&
139139
status == limatype.StatusRunning {
140140
_ = stopVM(ctx, distroName)
141141
}
@@ -207,13 +207,13 @@ func unregisterVM(ctx context.Context, distroName string) error {
207207
// Windows Subsystem for Linux has no installed distributions.
208208
// Distributions can be installed by visiting the Microsoft Store:
209209
// https://aka.ms/wslstore
210-
func getWslStatus(instName string) (string, error) {
210+
func getWslStatus(ctx context.Context, instName string) (string, error) {
211211
distroName := "lima-" + instName
212212
out, err := executil.RunUTF16leCommand([]string{
213213
"wsl.exe",
214214
"--list",
215215
"--verbose",
216-
})
216+
}, executil.WithContext(ctx))
217217
if err != nil {
218218
return "", fmt.Errorf("failed to run `wsl --list --verbose`, err: %w (out=%q)", err, out)
219219
}

pkg/driver/wsl2/wsl_driver_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (l *LimaWslDriver) BootScripts() (map[string][]byte, error) {
182182
}
183183

184184
func (l *LimaWslDriver) InspectStatus(ctx context.Context, inst *limatype.Instance) string {
185-
status, err := getWslStatus(inst.Name)
185+
status, err := getWslStatus(ctx, inst.Name)
186186
if err != nil {
187187
inst.Status = limatype.StatusBroken
188188
inst.Errors = append(inst.Errors, err)
@@ -206,7 +206,7 @@ func (l *LimaWslDriver) InspectStatus(ctx context.Context, inst *limatype.Instan
206206

207207
func (l *LimaWslDriver) Delete(ctx context.Context) error {
208208
distroName := "lima-" + l.Instance.Name
209-
status, err := getWslStatus(l.Instance.Name)
209+
status, err := getWslStatus(ctx, l.Instance.Name)
210210
if err != nil {
211211
return err
212212
}
@@ -221,7 +221,7 @@ func (l *LimaWslDriver) Delete(ctx context.Context) error {
221221

222222
func (l *LimaWslDriver) Start(ctx context.Context) (chan error, error) {
223223
logrus.Infof("Starting WSL VM")
224-
status, err := getWslStatus(l.Instance.Name)
224+
status, err := getWslStatus(ctx, l.Instance.Name)
225225
if err != nil {
226226
return nil, err
227227
}

0 commit comments

Comments
 (0)