From 6cadeb41fc2ac71ce88c79ce8fb0364113beae0a Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Fri, 1 May 2015 15:50:29 -0500 Subject: [PATCH] Pass kill signal to ptrace_detach --- proctl/ptrace_darwin.go | 8 ++++++++ proctl/ptrace_linux.go | 8 ++++++++ service/debugger/debugger.go | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/proctl/ptrace_darwin.go b/proctl/ptrace_darwin.go index ff09541b..7cf40c5e 100644 --- a/proctl/ptrace_darwin.go +++ b/proctl/ptrace_darwin.go @@ -6,6 +6,14 @@ import ( sys "golang.org/x/sys/unix" ) +func PtraceDetach(tid, sig int) error { + _, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PT_DETACH, uintptr(tid), 1, uintptr(sig), 0, 0) + if err != syscall.Errno(0) { + return err + } + return nil +} + func PtraceCont(tid, sig int) error { _, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PTRACE_CONT, uintptr(tid), 1, uintptr(sig), 0, 0) if err != syscall.Errno(0) { diff --git a/proctl/ptrace_linux.go b/proctl/ptrace_linux.go index 09334859..4c5b46fb 100644 --- a/proctl/ptrace_linux.go +++ b/proctl/ptrace_linux.go @@ -7,6 +7,14 @@ import ( sys "golang.org/x/sys/unix" ) +func PtraceDetach(tid, sig int) error { + _, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PTRACE_DETACH, uintptr(tid), 1, uintptr(sig), 0, 0) + if err != syscall.Errno(0) { + return err + } + return nil +} + func PtraceCont(tid, sig int) error { return sys.PtraceCont(tid, sig) } diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 71fd53f1..8db60c7a 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -137,7 +137,7 @@ func (d *Debugger) Run() error { // Kill the process if requested if s.KillProcess { - if err := proctl.PtraceCont(d.process.Pid, int(sys.SIGINT)); err == nil { + if err := proctl.PtraceDetach(d.process.Pid, int(sys.SIGINT)); err == nil { log.Print("killed process") } else { log.Printf("couldn't kill process: %s", err) @@ -145,7 +145,7 @@ func (d *Debugger) Run() error { } else { // Detach if !d.process.Exited() { - if err := sys.PtraceDetach(d.process.Pid); err == nil { + if err := proctl.PtraceDetach(d.process.Pid, 0); err == nil { log.Print("detached from process") } else { log.Printf("couldn't detach from process: %s", err)