Skip to content

Commit 092c99e

Browse files
committed
Optionally pass limactl filename to instance.Start()
This needed if the `instance.Start()` call is made in a different executable. Signed-off-by: Jan Dubois <[email protected]>
1 parent 69bd4e7 commit 092c99e

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

cmd/limactl/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func editAction(cmd *cobra.Command, args []string) error {
154154
if err != nil {
155155
return err
156156
}
157-
return instance.Start(ctx, inst, false)
157+
return instance.Start(ctx, inst, "", false)
158158
}
159159

160160
func askWhetherToStart() (bool, error) {

cmd/limactl/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ func startAction(cmd *cobra.Command, args []string) error {
501501
ctx = instance.WithWatchHostAgentTimeout(ctx, timeout)
502502
}
503503

504-
return instance.Start(ctx, inst, launchHostAgentForeground)
504+
return instance.Start(ctx, inst, "", launchHostAgentForeground)
505505
}
506506

507507
func createBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {

pkg/instance/start.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func Prepare(ctx context.Context, inst *store.Instance) (*Prepared, error) {
117117

118118
// Start starts the instance.
119119
// Start calls Prepare by itself, so you do not need to call Prepare manually before calling Start.
120-
func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground bool) error {
120+
func Start(ctx context.Context, inst *store.Instance, limactl string, launchHostAgentForeground bool) error {
121121
haPIDPath := filepath.Join(inst.Dir, filenames.HostAgentPID)
122122
if _, err := os.Stat(haPIDPath); !errors.Is(err, os.ErrNotExist) {
123123
return fmt.Errorf("instance %q seems running (hint: remove %q if the instance is not actually running)", inst.Name, haPIDPath)
@@ -150,9 +150,11 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
150150
return err
151151
}
152152

153-
self, err := os.Executable()
154-
if err != nil {
155-
return err
153+
if limactl == "" {
154+
limactl, err = os.Executable()
155+
if err != nil {
156+
return err
157+
}
156158
}
157159
haStdoutPath := filepath.Join(inst.Dir, filenames.HostAgentStdoutLog)
158160
haStderrPath := filepath.Join(inst.Dir, filenames.HostAgentStderrLog)
@@ -188,7 +190,7 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
188190
args = append(args, "--nerdctl-archive", prepared.NerdctlArchiveCache)
189191
}
190192
args = append(args, inst.Name)
191-
haCmd := exec.CommandContext(ctx, self, args...)
193+
haCmd := exec.CommandContext(ctx, limactl, args...)
192194

193195
if launchHostAgentForeground {
194196
haCmd.SysProcAttr = executil.ForegroundSysProcAttr
@@ -220,7 +222,7 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
220222
return err
221223
}
222224
}
223-
if err := syscall.Exec(self, haCmd.Args, haCmd.Environ()); err != nil {
225+
if err := syscall.Exec(limactl, haCmd.Args, haCmd.Environ()); err != nil {
224226
return err
225227
}
226228
} else if err := haCmd.Start(); err != nil {

0 commit comments

Comments
 (0)