mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 04:13:11 +00:00
strace: Update ptrace() usage
ptrace with PT_TRACEME was updated to also stop the traced thread on exit from execve.
This commit is contained in:
parent
479348c9e7
commit
8e87d340c3
|
@ -60,11 +60,14 @@ int main(int argc, char** argv)
|
|||
if (argc == 1)
|
||||
return usage();
|
||||
|
||||
bool spawned_new_process = false;
|
||||
|
||||
if (!strcmp(argv[1], "-p")) {
|
||||
if (argc != 3)
|
||||
return usage();
|
||||
g_pid = atoi(argv[2]);
|
||||
} else {
|
||||
spawned_new_process = true;
|
||||
int pid = fork();
|
||||
if (!pid) {
|
||||
if (ptrace(PT_TRACE_ME, 0, 0, 0) == -1) {
|
||||
|
@ -100,6 +103,18 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (spawned_new_process) {
|
||||
|
||||
if (ptrace(PT_CONTINUE, g_pid, 0, 0) < 0) {
|
||||
perror("continue");
|
||||
return 1;
|
||||
}
|
||||
if (waitpid(g_pid, nullptr, WSTOPPED) != g_pid) {
|
||||
perror("wait_pid");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (ptrace(PT_SYSCALL, g_pid, 0, 0) == -1) {
|
||||
if (errno == ESRCH)
|
||||
|
|
Loading…
Reference in a new issue