From ea31ee971714cc4df45e98f7c0a71d884486fc3e Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Tue, 17 Dec 2024 14:10:25 -0800 Subject: [PATCH] rdctl: Don't use process groups on Linux Disable killing all processes in the process on Linux, as Electron does not create a new process group when running from the RPM/deb package. Leave it using process groups on macOS, as launchd still does it. It is expected that we will revert this once we sort out process groups on Linux. Signed-off-by: Mark Yen --- src/go/rdctl/cmd/internalProcessWaitKill.go | 7 ++++++ src/go/rdctl/pkg/shutdown/shutdown.go | 26 ++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/go/rdctl/cmd/internalProcessWaitKill.go b/src/go/rdctl/cmd/internalProcessWaitKill.go index b581d21086f..8836fcdf7cd 100644 --- a/src/go/rdctl/cmd/internalProcessWaitKill.go +++ b/src/go/rdctl/cmd/internalProcessWaitKill.go @@ -21,6 +21,7 @@ package cmd import ( "fmt" + "runtime" "github.com/rancher-sandbox/rancher-desktop/src/go/rdctl/pkg/process" "github.com/spf13/cobra" @@ -39,6 +40,12 @@ exit, and once it does, terminates all processes within the same process group.` if err != nil { return fmt.Errorf("failed to get process ID: %w", err) } + if runtime.GOOS == "linux" { + // TODO: We can't use the process group on Linux, because Electron does + // not always create a new one. But for now still wait for the + // process to exit + return process.WaitForProcess(pid) + } return process.KillProcessGroup(pid, true) }, } diff --git a/src/go/rdctl/pkg/shutdown/shutdown.go b/src/go/rdctl/pkg/shutdown/shutdown.go index 9c048e9255e..2e4a3f02618 100644 --- a/src/go/rdctl/pkg/shutdown/shutdown.go +++ b/src/go/rdctl/pkg/shutdown/shutdown.go @@ -237,17 +237,21 @@ func terminateRancherDesktopFunc(appDir string) func(context.Context) error { return func(ctx context.Context) error { var errors *multierror.Error - errors = multierror.Append(errors, (func() error { - mainExe, err := p.GetMainExecutable(ctx) - if err != nil { - return err - } - pid, err := process.FindPidOfProcess(mainExe) - if err != nil { - return err - } - return process.KillProcessGroup(pid, false) - })()) + // TODO: We can't use the process group on Linux, because Electron does + // not always create a new one. + if runtime.GOOS != "linux" { + errors = multierror.Append(errors, (func() error { + mainExe, err := p.GetMainExecutable(ctx) + if err != nil { + return err + } + pid, err := process.FindPidOfProcess(mainExe) + if err != nil { + return err + } + return process.KillProcessGroup(pid, false) + })()) + } errors = multierror.Append(errors, process.TerminateProcessInDirectory(appDir, true))