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:
parent
f32ce1b21d
commit
ac1aa98378
@ -306,10 +306,6 @@ func (p *Process) Halt() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Kill() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Process) Pid() int {
|
func (p *Process) Pid() int {
|
||||||
return p.core.Pid
|
return p.core.Pid
|
||||||
}
|
}
|
||||||
|
@ -745,24 +745,14 @@ func (p *Process) Halt() error {
|
|||||||
return p.conn.sendCtrlC()
|
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 {
|
func (p *Process) Detach(kill bool) error {
|
||||||
if kill {
|
if kill && !p.exited {
|
||||||
if err := p.Kill(); err != nil {
|
err := p.conn.kill()
|
||||||
|
if err != nil {
|
||||||
if _, exited := err.(proc.ProcessExitedError); !exited {
|
if _, exited := err.(proc.ProcessExitedError); !exited {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
p.exited = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !p.exited {
|
if !p.exited {
|
||||||
|
@ -91,7 +91,6 @@ type ProcessManipulation interface {
|
|||||||
// after a call to RequestManualStop.
|
// after a call to RequestManualStop.
|
||||||
CheckAndClearManualStopRequest() bool
|
CheckAndClearManualStopRequest() bool
|
||||||
Halt() error
|
Halt() error
|
||||||
Kill() error
|
|
||||||
Detach(bool) error
|
Detach(bool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ func (dbp *Process) Detach(kill bool) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if kill && dbp.childProcess {
|
if kill && dbp.childProcess {
|
||||||
err := dbp.Kill()
|
err := dbp.kill()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ func Attach(pid int) (*Process, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Kill kills the process.
|
// Kill kills the process.
|
||||||
func (dbp *Process) Kill() (err error) {
|
func (dbp *Process) kill() (err error) {
|
||||||
if dbp.exited {
|
if dbp.exited {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -98,8 +98,8 @@ func Attach(pid int) (*Process, error) {
|
|||||||
return dbp, nil
|
return dbp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill kills the target process.
|
// kill kills the target process.
|
||||||
func (dbp *Process) Kill() (err error) {
|
func (dbp *Process) kill() (err error) {
|
||||||
if dbp.exited {
|
if dbp.exited {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -170,8 +170,8 @@ func Attach(pid int) (*Process, error) {
|
|||||||
return dbp, nil
|
return dbp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill kills the process.
|
// kill kills the process.
|
||||||
func (dbp *Process) Kill() error {
|
func (dbp *Process) kill() error {
|
||||||
if dbp.exited {
|
if dbp.exited {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -968,20 +968,6 @@ func TestKill(t *testing.T) {
|
|||||||
// k command presumably works but leaves the process around?
|
// k command presumably works but leaves the process around?
|
||||||
return
|
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) {
|
withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) {
|
||||||
if err := p.Detach(true); err != nil {
|
if err := p.Detach(true); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -2086,8 +2072,7 @@ func TestUnsupportedArch(t *testing.T) {
|
|||||||
case proc.UnsupportedLinuxArchErr, proc.UnsupportedWindowsArchErr, proc.UnsupportedDarwinArchErr:
|
case proc.UnsupportedLinuxArchErr, proc.UnsupportedWindowsArchErr, proc.UnsupportedDarwinArchErr:
|
||||||
// all good
|
// all good
|
||||||
case nil:
|
case nil:
|
||||||
p.Halt()
|
p.Detach(true)
|
||||||
p.Kill()
|
|
||||||
t.Fatal("Launch is expected to fail, but succeeded")
|
t.Fatal("Launch is expected to fail, but succeeded")
|
||||||
default:
|
default:
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -46,7 +46,7 @@ func TestIssue419(t *testing.T) {
|
|||||||
if p.Pid() <= 0 {
|
if p.Pid() <= 0 {
|
||||||
// if we don't stop the inferior the test will never finish
|
// if we don't stop the inferior the test will never finish
|
||||||
p.RequestManualStop()
|
p.RequestManualStop()
|
||||||
err := p.Kill()
|
err := p.Detach(true)
|
||||||
errChan <- errIssue419{pid: p.Pid(), err: err}
|
errChan <- errIssue419{pid: p.Pid(), err: err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ func TestIssue419(t *testing.T) {
|
|||||||
errChan <- proc.Continue(p)
|
errChan <- proc.Continue(p)
|
||||||
})
|
})
|
||||||
|
|
||||||
for i :=0; i<2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
err := <-errChan
|
err := <-errChan
|
||||||
|
|
||||||
if v, ok := err.(errIssue419); ok {
|
if v, ok := err.(errIssue419); ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user