mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-31 23:19:40 +02:00
Bump kill package (#4137)
Closes https://github.com/jesseduffield/lazygit/issues/3008 This should reduce the instances of killing random processes on windows. See https://github.com/jesseduffield/kill/pull/1 - **PR Description** - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [ ] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [x] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [x] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [x] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc <!-- Be sure to name your PR with an imperative e.g. 'Add worktrees view' see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for examples -->
This commit is contained in:
commit
03d7bc854e
2
go.mod
2
go.mod
@ -17,7 +17,7 @@ require (
|
||||
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68
|
||||
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20241223111608-9967d0e928a0
|
||||
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
|
||||
github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a
|
||||
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5
|
||||
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
|
||||
|
4
go.sum
4
go.sum
@ -190,8 +190,8 @@ github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d h1:bO+Om
|
||||
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20241223111608-9967d0e928a0 h1:R29+E15wHqTDBfZxmzCLu0x34j5ljsXWT/DhR+2YiOU=
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20241223111608-9967d0e928a0/go.mod h1:XtEbqCbn45keRXEu+OMZkjN5gw6AEob59afsgHjokZ8=
|
||||
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
|
||||
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
|
||||
github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a h1:UDeJ3EBk04bXDLOPvuqM3on8HvyJfISw0+UMqW+0a4g=
|
||||
github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a/go.mod h1:FSWDLKT0NQpntbDd1H3lbz51fhCVlMzy/J0S6nM727Q=
|
||||
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY=
|
||||
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5/go.mod h1:qxN4mHOAyeIDLP7IK7defgPClM/z1Kze8VVQiaEjzsQ=
|
||||
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e h1:uw/oo+kg7t/oeMs6sqlAwr85ND/9cpO3up3VxphxY0U=
|
||||
|
44
vendor/github.com/jesseduffield/kill/kill_windows.go
generated
vendored
44
vendor/github.com/jesseduffield/kill/kill_windows.go
generated
vendored
@ -3,12 +3,37 @@
|
||||
package kill
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/windows"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const PROCESS_ALL_ACCESS = windows.STANDARD_RIGHTS_REQUIRED | windows.SYNCHRONIZE | 0xffff
|
||||
|
||||
func GetWindowsHandle(pid int) (handle windows.Handle, err error) {
|
||||
handle, err = windows.OpenProcess(PROCESS_ALL_ACCESS, false, uint32(pid))
|
||||
return
|
||||
}
|
||||
|
||||
func GetCreationTime(pid int) (time int64, err error) {
|
||||
handle, err := GetWindowsHandle(pid)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer closeHandle(HANDLE(handle))
|
||||
|
||||
var u syscall.Rusage
|
||||
err = syscall.GetProcessTimes(syscall.Handle(handle), &u.CreationTime, &u.ExitTime, &u.KernelTime, &u.UserTime)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
time = u.CreationTime.Nanoseconds()
|
||||
return
|
||||
}
|
||||
|
||||
// Kill kills a process, along with any child processes it may have spawned.
|
||||
func Kill(cmd *exec.Cmd) error {
|
||||
if cmd.Process == nil {
|
||||
@ -16,7 +41,12 @@ func Kill(cmd *exec.Cmd) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
pids := Getppids(uint32(cmd.Process.Pid))
|
||||
ptime, err := GetCreationTime(cmd.Process.Pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pids := Getppids(uint32(cmd.Process.Pid), ptime)
|
||||
for _, pid := range pids {
|
||||
pro, err := os.FindProcess(int(pid))
|
||||
if err != nil {
|
||||
@ -70,7 +100,7 @@ var (
|
||||
procCloseHandle = modkernel32.NewProc("CloseHandle")
|
||||
)
|
||||
|
||||
func Getppids(pid uint32) []uint32 {
|
||||
func Getppids(pid uint32, ptime int64) []uint32 {
|
||||
infos, err := GetProcs()
|
||||
if err != nil {
|
||||
return []uint32{pid}
|
||||
@ -83,7 +113,15 @@ func Getppids(pid uint32) []uint32 {
|
||||
for index < length {
|
||||
for _, info := range infos {
|
||||
if info.PPid == pids[index] {
|
||||
pids = append(pids, info.Pid)
|
||||
ctime, err := GetCreationTime(int(info.Pid))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if ctime >= ptime {
|
||||
// Only appending if child is newer than parent, otherwise PPid was reused
|
||||
pids = append(pids, info.Pid)
|
||||
}
|
||||
}
|
||||
}
|
||||
index += 1
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -175,7 +175,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/noder
|
||||
# github.com/jesseduffield/gocui v0.3.1-0.20241223111608-9967d0e928a0
|
||||
## explicit; go 1.12
|
||||
github.com/jesseduffield/gocui
|
||||
# github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
|
||||
# github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a
|
||||
## explicit; go 1.18
|
||||
github.com/jesseduffield/kill
|
||||
# github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5
|
||||
|
Loading…
x
Reference in New Issue
Block a user