proc: remove proc.Process.Kill

the proper way to kill the target process is to pass true to Detach.
Everything except old test code did that already.
This commit is contained in:
aarzilli 2018-02-13 15:42:14 +01:00 committed by Derek Parker
parent f32ce1b21d
commit ac1aa98378
9 changed files with 13 additions and 43 deletions

@ -306,10 +306,6 @@ func (p *Process) Halt() error {
return nil
}
func (p *Process) Kill() error {
return nil
}
func (p *Process) Pid() int {
return p.core.Pid
}

@ -745,24 +745,14 @@ func (p *Process) Halt() error {
return p.conn.sendCtrlC()
}
func (p *Process) Kill() error {
if p.exited {
return nil
}
err := p.conn.kill()
if _, exited := err.(proc.ProcessExitedError); exited {
p.exited = true
return nil
}
return err
}
func (p *Process) Detach(kill bool) error {
if kill {
if err := p.Kill(); err != nil {
if kill && !p.exited {
err := p.conn.kill()
if err != nil {
if _, exited := err.(proc.ProcessExitedError); !exited {
return err
}
p.exited = true
}
}
if !p.exited {

@ -91,7 +91,6 @@ type ProcessManipulation interface {
// after a call to RequestManualStop.
CheckAndClearManualStopRequest() bool
Halt() error
Kill() error
Detach(bool) error
}

@ -79,7 +79,7 @@ func (dbp *Process) Detach(kill bool) (err error) {
return nil
}
if kill && dbp.childProcess {
err := dbp.Kill()
err := dbp.kill()
if err != nil {
return err
}

@ -166,7 +166,7 @@ func Attach(pid int) (*Process, error) {
}
// Kill kills the process.
func (dbp *Process) Kill() (err error) {
func (dbp *Process) kill() (err error) {
if dbp.exited {
return nil
}

@ -98,8 +98,8 @@ func Attach(pid int) (*Process, error) {
return dbp, nil
}
// Kill kills the target process.
func (dbp *Process) Kill() (err error) {
// kill kills the target process.
func (dbp *Process) kill() (err error) {
if dbp.exited {
return nil
}

@ -170,8 +170,8 @@ func Attach(pid int) (*Process, error) {
return dbp, nil
}
// Kill kills the process.
func (dbp *Process) Kill() error {
// kill kills the process.
func (dbp *Process) kill() error {
if dbp.exited {
return nil
}

@ -968,20 +968,6 @@ func TestKill(t *testing.T) {
// k command presumably works but leaves the process around?
return
}
withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) {
if err := p.Kill(); err != nil {
t.Fatal(err)
}
if !p.Exited() {
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())
}
}
})
withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) {
if err := p.Detach(true); err != nil {
t.Fatal(err)
@ -2086,8 +2072,7 @@ func TestUnsupportedArch(t *testing.T) {
case proc.UnsupportedLinuxArchErr, proc.UnsupportedWindowsArchErr, proc.UnsupportedDarwinArchErr:
// all good
case nil:
p.Halt()
p.Kill()
p.Detach(true)
t.Fatal("Launch is expected to fail, but succeeded")
default:
t.Fatal(err)

@ -46,7 +46,7 @@ func TestIssue419(t *testing.T) {
if p.Pid() <= 0 {
// if we don't stop the inferior the test will never finish
p.RequestManualStop()
err := p.Kill()
err := p.Detach(true)
errChan <- errIssue419{pid: p.Pid(), err: err}
return
}
@ -57,7 +57,7 @@ func TestIssue419(t *testing.T) {
errChan <- proc.Continue(p)
})
for i :=0; i<2; i++ {
for i := 0; i < 2; i++ {
err := <-errChan
if v, ok := err.(errIssue419); ok {