Skip to content

Commit

Permalink
fix: 安卓平台无法正常杀死内置Lagrange子进程 (sealdice#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fripine authored Jul 10, 2024
1 parent b5e861a commit 8fe0338
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
17 changes: 17 additions & 0 deletions utils/procs/killprocs_android.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build android
// +build android

package procs

import (
"syscall"
)

func (p *Process) KillProcess() error {
cmd := p.Cmd
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}
func (p *Process) Setpgid() {
cmd := p.Cmd
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
}
11 changes: 11 additions & 0 deletions utils/procs/killprocs_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !android
// +build !android

package procs

func (p *Process) KillProcess() error {
cmd := p.Cmd
return cmd.Process.Kill()
}
func (p *Process) Setpgid() {
}
3 changes: 2 additions & 1 deletion utils/procs/procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (p *Process) Start() error {
cmd.Env = p.Env
}
p.Cmd = cmd
p.Setpgid()
stdin, err := cmd.StdinPipe()
if err != nil {
return err
Expand Down Expand Up @@ -135,7 +136,7 @@ func (p *Process) Stop() error {
return nil
}

err := cmd.Process.Kill()
err := p.KillProcess()
if err != nil {
return err
}
Expand Down

0 comments on commit 8fe0338

Please sign in to comment.