| 73 | } |
| 74 | |
| 75 | bool KittyTraceMgr::detach() |
| 76 | { |
| 77 | _attached = false; |
| 78 | |
| 79 | if (!isAttached()) |
| 80 | return true; |
| 81 | |
| 82 | while (true) |
| 83 | { |
| 84 | int status = 0; |
| 85 | if (waitpid(_pid, &status, __WALL | WNOHANG) <= 0) |
| 86 | break; |
| 87 | } |
| 88 | |
| 89 | errno = 0; |
| 90 | if (ptrace(PTRACE_DETACH, _pid, nullptr, nullptr) == -1L) |
| 91 | { |
| 92 | KITTY_LOGE("PTRACE_DETACH failed for pid %d. \"%s\".", _pid, strerror(errno)); |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | while (true) |
| 97 | { |
| 98 | int status = 0; |
| 99 | if (waitpid(_pid, &status, __WALL | WNOHANG) <= 0) |
| 100 | break; |
| 101 | } |
| 102 | |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | bool KittyTraceMgr::stop() |
| 107 | { |