Skip to content

Commit 159d1ec

Browse files
committed
Run usernet process in background
Similar to the how we run the hostagent process[1], we want to run the usernet process in the background. Now a program using killpg to cleanup child processes will not terminate the usernet process. Example run with this change: % ps -o pid,pgid,ppid,command PID PGID PPID COMMAND 55768 55768 55767 -zsh 56126 56126 55768 limactl start userv2.yaml --tty=0 56128 56128 56126 /Users/nsoffer/src/lima/_output/bin/limactl usernet ... 56131 56131 56126 /Users/nsoffer/src/lima/_output/bin/limactl hostagent ... % ps -o pid,pgid,ppid,command PID PGID PPID COMMAND 55768 55768 55767 -zsh 56128 56128 1 /Users/nsoffer/src/lima/_output/bin/limactl usernet ... 56131 56131 1 /Users/nsoffer/src/lima/_output/bin/limactl hostagent ... [1] #2574 Signed-off-by: Nir Soffer <[email protected]>
1 parent 52f5ad3 commit 159d1ec

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

pkg/instance/ha_cmd_opts_others.go renamed to pkg/executil/opts_others.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !windows
22

3-
package instance
3+
package executil
44

55
import (
66
"syscall"

pkg/instance/ha_cmd_opts_windows.go renamed to pkg/executil/opts_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package instance
1+
package executil
22

33
import (
44
"syscall"

pkg/instance/start.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/coreos/go-semver/semver"
1818
"github.com/lima-vm/lima/pkg/driver"
1919
"github.com/lima-vm/lima/pkg/driverutil"
20+
"github.com/lima-vm/lima/pkg/executil"
2021
"github.com/lima-vm/lima/pkg/osutil"
2122
"github.com/lima-vm/lima/pkg/qemu"
2223
"github.com/lima-vm/lima/pkg/qemu/entitlementutil"
@@ -191,9 +192,9 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
191192
haCmd := exec.CommandContext(ctx, self, args...)
192193

193194
if launchHostAgentForeground {
194-
haCmd.SysProcAttr = ForegroundSysProcAttr
195+
haCmd.SysProcAttr = executil.ForegroundSysProcAttr
195196
} else {
196-
haCmd.SysProcAttr = BackgroundSysProcAttr
197+
haCmd.SysProcAttr = executil.BackgroundSysProcAttr
197198
}
198199

199200
haCmd.Stdout = haStdoutW

pkg/networks/usernet/recoincile.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16+
"github.com/lima-vm/lima/pkg/executil"
1617
"github.com/lima-vm/lima/pkg/lockutil"
1718
"github.com/lima-vm/lima/pkg/store"
1819
"github.com/lima-vm/lima/pkg/store/dirnames"
@@ -81,6 +82,7 @@ func Start(ctx context.Context, name string) error {
8182
args = append(args, "--leases", leasesString)
8283
}
8384
cmd := exec.CommandContext(ctx, self, args...)
85+
cmd.SysProcAttr = executil.BackgroundSysProcAttr
8486

8587
stdoutPath := filepath.Join(usernetDir, fmt.Sprintf("%s.%s.%s.log", "usernet", name, "stdout"))
8688
stderrPath := filepath.Join(usernetDir, fmt.Sprintf("%s.%s.%s.log", "usernet", name, "stderr"))

0 commit comments

Comments
 (0)