fix killing our own fucking PID
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//go:build windows
|
||||
|
||||
package capture
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBackstageShouldKillPID(t *testing.T) {
|
||||
const currentPID uint32 = 42
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
pid uint32
|
||||
want bool
|
||||
}{
|
||||
{name: "invalid pid", pid: 0, want: false},
|
||||
{name: "agent process", pid: currentPID, want: false},
|
||||
{name: "backstage process", pid: 99, want: true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := backstageShouldKillPID(tt.pid, currentPID); got != tt.want {
|
||||
t.Fatalf("backstageShouldKillPID(%d, %d) = %v, want %v", tt.pid, currentPID, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"image"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -653,6 +654,7 @@ func BackstageKillAll() error {
|
||||
return fmt.Errorf("backstage desktop not initialized")
|
||||
}
|
||||
|
||||
currentPID := uint32(os.Getpid())
|
||||
pids := make(map[uint32]struct{})
|
||||
cb := syscall.NewCallback(func(hwnd, _ uintptr) uintptr {
|
||||
if backstageIsDWMHost(hwnd) {
|
||||
@@ -660,7 +662,7 @@ func BackstageKillAll() error {
|
||||
}
|
||||
var pid uint32
|
||||
procGetWindowThreadProcessId.Call(hwnd, uintptr(unsafe.Pointer(&pid)))
|
||||
if pid != 0 {
|
||||
if backstageShouldKillPID(pid, currentPID) {
|
||||
pids[pid] = struct{}{}
|
||||
}
|
||||
return 1 // continue enumeration
|
||||
@@ -681,6 +683,10 @@ func BackstageKillAll() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func backstageShouldKillPID(pid, currentPID uint32) bool {
|
||||
return pid != 0 && pid != currentPID
|
||||
}
|
||||
|
||||
func BackstageAutoStartExplorer() error {
|
||||
if backstageExplorerStarted {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user