Skip to content

Commit 47a3d7b

Browse files
committed
Run in a new process group when not using --foreground
Previously the hostagenet process was running in the foreground even when not using the --foreground option. It was using the same pgid of limactl process. If the guest was running, but limactl was interrupted the hostagent received the signal and was killed, stopping the VM. A simple way to fix this issue is to start the hostagent process in a new process group. This way it will be killed sending signals to the limactl process group. It looks like this is already implemented for Windows based on the docs for syscall.CREATE_NEW_PROCESS_GROUP[1]. Example run with this change: % ps -o pid,pgid,ppid,command PID PGID PPID COMMAND 39442 39442 39440 -zsh 63233 63233 39442 _output/bin/limactl start --vm-type vz --tty=false 63299 63299 63233 /Users/nsoffer/src/lima/_output/bin/limactl hostagent ... We can improve this later by adding an option to daemonize the hostagent process (like qemu --daemonize). [1] https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags Fixes #2573 Signed-off-by: Nir Soffer <[email protected]>
1 parent 726f61d commit 47a3d7b

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

pkg/instance/ha_cmd_opts_others.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ import (
66
"syscall"
77
)
88

9-
var SysProcAttr = &syscall.SysProcAttr{}
9+
var (
10+
ForegroundSysProcAttr = &syscall.SysProcAttr{}
11+
BackgroundSysProcAttr = &syscall.SysProcAttr{Setpgid: true}
12+
)

pkg/instance/ha_cmd_opts_windows.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"syscall"
55
)
66

7-
var SysProcAttr = &syscall.SysProcAttr{
8-
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
9-
}
7+
var (
8+
ForegroundSysProcAttr = &syscall.SysProcAttr{}
9+
BackgroundSysProcAttr = &syscall.SysProcAttr{
10+
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
11+
}
12+
)

pkg/instance/start.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
189189
}
190190
args = append(args, inst.Name)
191191
haCmd := exec.CommandContext(ctx, self, args...)
192-
haCmd.SysProcAttr = SysProcAttr
192+
193+
if launchHostAgentForeground {
194+
haCmd.SysProcAttr = ForegroundSysProcAttr
195+
} else {
196+
haCmd.SysProcAttr = BackgroundSysProcAttr
197+
}
193198

194199
haCmd.Stdout = haStdoutW
195200
haCmd.Stderr = haStderrW

0 commit comments

Comments
 (0)