|
4 | 4 | package store |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "context" |
7 | 8 | "fmt" |
8 | 9 | "os/exec" |
9 | 10 | "regexp" |
@@ -124,21 +125,22 @@ func GetWslStatus(instName string) (string, error) { |
124 | 125 | // But busybox hostname does not implement --all-ip-addresses: |
125 | 126 | // hostname: unrecognized option: I |
126 | 127 | func GetSSHAddress(instName string) (string, error) { |
| 128 | + ctx := context.TODO() |
127 | 129 | distroName := "lima-" + instName |
128 | 130 | // 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`) |
130 | 132 | out, err := cmd.CombinedOutput() |
131 | 133 | if err == nil { |
132 | 134 | return strings.TrimSpace(string(out)), nil |
133 | 135 | } |
134 | 136 | // 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}'`) |
136 | 138 | out, err = cmd.CombinedOutput() |
137 | 139 | if err == nil { |
138 | 140 | return strings.TrimSpace(string(out)), nil |
139 | 141 | } |
140 | 142 | // fallback |
141 | | - cmd = exec.Command("wsl.exe", "-d", distroName, "hostname", "-i") |
| 143 | + cmd = exec.CommandContext(ctx, "wsl.exe", "-d", distroName, "hostname", "-i") |
142 | 144 | out, err = cmd.CombinedOutput() |
143 | 145 | if err != nil || strings.HasPrefix(string(out), "127.") { |
144 | 146 | return "", fmt.Errorf("failed to get hostname for instance %q, err: %w (out=%q)", instName, err, string(out)) |
|
0 commit comments