Skip to content

Commit

Permalink
rdctl: Don't use process groups on Linux
Browse files Browse the repository at this point in the history
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 <mark.yen@suse.com>
  • Loading branch information
mook-as committed Dec 18, 2024
1 parent 7621be0 commit 4fdc6c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
18 changes: 18 additions & 0 deletions src/go/rdctl/cmd/internalProcessWaitKill.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ limitations under the License.
package cmd

import (
"errors"
"fmt"
"os"
"runtime"
"syscall"

"github.com/rancher-sandbox/rancher-desktop/src/go/rdctl/pkg/process"
"github.com/spf13/cobra"
Expand All @@ -39,6 +43,20 @@ 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.
proc, err := os.FindProcess(pid)
if err != nil {
return fmt.Errorf("failed to find process for pid %d: %w", pid, err)
}
// The pid might not exist even if we did not receive an error.
err = proc.Signal(syscall.SIGTERM)
if err != nil && !errors.Is(err, os.ErrProcessDone) {
return fmt.Errorf("failed to terminate process %d: %w", pid, err)
}
return nil
}
return process.KillProcessGroup(pid, true)
},
}
Expand Down
26 changes: 15 additions & 11 deletions src/go/rdctl/pkg/shutdown/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 4fdc6c1

Please sign in to comment.