Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release-1.17: Obvious factory reset errors #7964

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/go/rdctl/cmd/internalProcessWaitKill.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ 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)
}
return process.WaitForProcessAndKillGroup(pid)
return process.KillProcessGroup(pid, true)
},
}

Expand Down
13 changes: 7 additions & 6 deletions src/go/rdctl/pkg/process/process_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,20 @@ func FindPidOfProcess(executable string) (int, error) {
return mainPid, nil
}

// Wait for the process identified by the given pid to exit, then kill all
// processes in the same process group. This blocks until the given process
// exits. If the given pid is 0, this is a no-op.
func WaitForProcessAndKillGroup(pid int) error {
// Kill the process group the given process belongs to. If wait is set, block
// until the target process exits first before doing so.
func KillProcessGroup(pid int, wait bool) error {
if pid == 0 {
return nil
}
pgid, err := unix.Getpgid(pid)
if err != nil {
return fmt.Errorf("failed to get process group id for %d: %w", pid, err)
}
if err = WaitForProcess(pid); err != nil {
return fmt.Errorf("failed to wait for process: %w", err)
if wait {
if err = WaitForProcess(pid); err != nil {
return fmt.Errorf("failed to wait for process: %w", err)
}
}
err = unix.Kill(-pgid, unix.SIGTERM)
if err != nil && !errors.Is(err, unix.ESRCH) {
Expand Down
13 changes: 8 additions & 5 deletions src/go/rdctl/pkg/process/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,10 @@ func FindPidOfProcess(executable string) (int, error) {
return mainPid, nil
}

// Wait for the process identified by the given pid to exit, then kill all
// processes in the same process group. This blocks until the given process
// exits.
func WaitForProcessAndKillGroup(pid int) error {
return errors.New("WaitForProcessAndKillGroup is not implemented on Windows")
// Kill the process group the given process belongs to. If wait is set, block
// until the target process exits first before doing so.
func KillProcessGroup(pid int, wait bool) error {
return errors.New("KillProcessGroup is not implemented on Windows")
}

// TerminateProcessInDirectory terminates all processes where the executable
Expand All @@ -428,6 +427,10 @@ func TerminateProcessInDirectory(directory string, force bool) error {
if err != nil {
pid = 0
}
if pid == uint32(os.Getpid()) {
// Skip terminating the current process.
return nil
}
relPath, err := filepath.Rel(directory, executablePath)
if err != nil {
// This may be because they're on different drives, network shares, etc.
Expand Down
2 changes: 1 addition & 1 deletion src/go/rdctl/pkg/shutdown/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func terminateRancherDesktopFunc(appDir string) func(context.Context) error {
if err != nil {
return err
}
return process.WaitForProcessAndKillGroup(pid)
return process.KillProcessGroup(pid, false)
})())

errors = multierror.Append(errors, process.TerminateProcessInDirectory(appDir, true))
Expand Down
Loading