diff --git a/lib/libproc/proc_util.c b/lib/libproc/proc_util.c --- a/lib/libproc/proc_util.c +++ b/lib/libproc/proc_util.c @@ -85,25 +85,21 @@ proc_detach(struct proc_handle *phdl, int reason) { int status; + int request; pid_t pid; if (phdl == NULL) return (EINVAL); if (reason == PRELEASE_HANG) return (EINVAL); - if (reason == PRELEASE_KILL) { - kill(proc_getpid(phdl), SIGKILL); - goto free; - } if ((phdl->flags & PATTACH_RDONLY) != 0) goto free; + request = (reason == PRELEASE_KILL) ? PT_KILL : PT_DETACH; pid = proc_getpid(phdl); - if (ptrace(PT_DETACH, pid, 0, 0) != 0 && errno == ESRCH) - goto free; - if (errno == EBUSY) { + if (ptrace(request, pid, 0, 0) != 0 && errno == EBUSY) { kill(pid, SIGSTOP); waitpid(pid, &status, WUNTRACED); - ptrace(PT_DETACH, pid, 0, 0); + ptrace(request, pid, 0, 0); kill(pid, SIGCONT); } free: