proc/native: Detach should use Kill with child processes we want killed (#822)
While implementing the gdbserial backend everything was changed to call Detach to "close" a process so that gdbserial could do its clean up in a single place. However the native implementation of Detach does not actually kill processes we launched. Fixes #821
This commit is contained in:
parent
f29b9edad2
commit
1f1535802e
@ -41,6 +41,7 @@ type Process struct {
|
||||
exited bool
|
||||
ptraceChan chan func()
|
||||
ptraceDoneChan chan interface{}
|
||||
childProcess bool // this process was launched, not attached to
|
||||
}
|
||||
|
||||
// New returns an initialized Process struct. Before returning,
|
||||
@ -71,6 +72,14 @@ func (dbp *Process) Detach(kill bool) (err error) {
|
||||
if dbp.exited {
|
||||
return nil
|
||||
}
|
||||
if kill && dbp.childProcess {
|
||||
err := dbp.Kill()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbp.bi.Close()
|
||||
return nil
|
||||
}
|
||||
if dbp.Running() {
|
||||
if err = dbp.Halt(); err != nil {
|
||||
return
|
||||
|
@ -75,6 +75,7 @@ func Launch(cmd []string, wd string) (*Process, error) {
|
||||
return nil, fmt.Errorf("could not fork/exec")
|
||||
}
|
||||
dbp.pid = pid
|
||||
dbp.childProcess = true
|
||||
for i := range argvSlice {
|
||||
C.free(unsafe.Pointer(argvSlice[i]))
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ func Launch(cmd []string, wd string) (*Process, error) {
|
||||
return nil, err
|
||||
}
|
||||
dbp.pid = process.Process.Pid
|
||||
dbp.childProcess = true
|
||||
_, _, err = dbp.wait(process.Process.Pid, 0)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("waiting for target execve failed: %s", err)
|
||||
|
@ -125,6 +125,7 @@ func Launch(cmd []string, wd string) (*Process, error) {
|
||||
sys.CloseHandle(sys.Handle(pi.Thread))
|
||||
|
||||
dbp.pid = int(pi.ProcessId)
|
||||
dbp.childProcess = true
|
||||
|
||||
return newDebugProcess(dbp, argv0Go)
|
||||
}
|
||||
|
@ -918,6 +918,20 @@ func TestKill(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) {
|
||||
if err := p.Detach(true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p.Exited() != true {
|
||||
t.Fatal("expected process to have exited")
|
||||
}
|
||||
if runtime.GOOS == "linux" {
|
||||
_, err := os.Open(fmt.Sprintf("/proc/%d/", p.Pid()))
|
||||
if err == nil {
|
||||
t.Fatal("process has not exited", p.Pid())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func testGSupportFunc(name string, t *testing.T, p proc.Process, fixture protest.Fixture) {
|
||||
|
Loading…
Reference in New Issue
Block a user