Skip to content

Commit

Permalink
Run usernet process in background
Browse files Browse the repository at this point in the history
Similar to the how we run the hostagent process, 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 ...

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs committed Sep 6, 2024
1 parent 536f375 commit 9a2f753
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build !windows

package instance
package executil

import (
"syscall"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instance
package executil

import (
"syscall"
Expand Down
5 changes: 3 additions & 2 deletions pkg/instance/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/coreos/go-semver/semver"
"github.com/lima-vm/lima/pkg/driver"
"github.com/lima-vm/lima/pkg/driverutil"
"github.com/lima-vm/lima/pkg/executil"
"github.com/lima-vm/lima/pkg/osutil"
"github.com/lima-vm/lima/pkg/qemu"
"github.com/lima-vm/lima/pkg/qemu/entitlementutil"
Expand Down Expand Up @@ -191,9 +192,9 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
haCmd := exec.CommandContext(ctx, self, args...)

if launchHostAgentForeground {
haCmd.SysProcAttr = ForegroundSysProcAttr
haCmd.SysProcAttr = executil.ForegroundSysProcAttr
} else {
haCmd.SysProcAttr = BackgroundSysProcAttr
haCmd.SysProcAttr = executil.BackgroundSysProcAttr
}

haCmd.Stdout = haStdoutW
Expand Down
2 changes: 2 additions & 0 deletions pkg/networks/usernet/recoincile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"time"

"github.com/lima-vm/lima/pkg/executil"
"github.com/lima-vm/lima/pkg/lockutil"
"github.com/lima-vm/lima/pkg/store"
"github.com/lima-vm/lima/pkg/store/dirnames"
Expand Down Expand Up @@ -81,6 +82,7 @@ func Start(ctx context.Context, name string) error {
args = append(args, "--leases", leasesString)
}
cmd := exec.CommandContext(ctx, self, args...)
cmd.SysProcAttr = executil.BackgroundSysProcAttr

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

0 comments on commit 9a2f753

Please sign in to comment.