Skip to content

Commit ca30c0d

Browse files
committed
Add a context argument to the wsl commands
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 8b84d9f commit ca30c0d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pkg/store/instance_windows.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package store
55

66
import (
7+
"context"
78
"fmt"
89
"os/exec"
910
"regexp"
@@ -124,21 +125,22 @@ func GetWslStatus(instName string) (string, error) {
124125
// But busybox hostname does not implement --all-ip-addresses:
125126
// hostname: unrecognized option: I
126127
func GetSSHAddress(instName string) (string, error) {
128+
ctx := context.TODO()
127129
distroName := "lima-" + instName
128130
// Ubuntu
129-
cmd := exec.Command("wsl.exe", "-d", distroName, "bash", "-c", `hostname -I | cut -d ' ' -f1`)
131+
cmd := exec.CommandContext(ctx, "wsl.exe", "-d", distroName, "bash", "-c", `hostname -I | cut -d ' ' -f1`)
130132
out, err := cmd.CombinedOutput()
131133
if err == nil {
132134
return strings.TrimSpace(string(out)), nil
133135
}
134136
// Alpine
135-
cmd = exec.Command("wsl.exe", "-d", distroName, "sh", "-c", `ip route get 1 | awk '{gsub("^.*src ",""); print $1; exit}'`)
137+
cmd = exec.CommandContext(ctx, "wsl.exe", "-d", distroName, "sh", "-c", `ip route get 1 | awk '{gsub("^.*src ",""); print $1; exit}'`)
136138
out, err = cmd.CombinedOutput()
137139
if err == nil {
138140
return strings.TrimSpace(string(out)), nil
139141
}
140142
// fallback
141-
cmd = exec.Command("wsl.exe", "-d", distroName, "hostname", "-i")
143+
cmd = exec.CommandContext(ctx, "wsl.exe", "-d", distroName, "hostname", "-i")
142144
out, err = cmd.CombinedOutput()
143145
if err != nil || strings.HasPrefix(string(out), "127.") {
144146
return "", fmt.Errorf("failed to get hostname for instance %q, err: %w (out=%q)", instName, err, string(out))

0 commit comments

Comments
 (0)