diff --git a/usr.bin/truss/setup.c b/usr.bin/truss/setup.c --- a/usr.bin/truss/setup.c +++ b/usr.bin/truss/setup.c @@ -205,12 +205,25 @@ static void detach_proc(pid_t pid) { + int sig, status; - /* stop the child so that we can detach */ + /* + * Stop the child so that we can detach. Filter out possible + * lingering SIGTRAP events buffered in the threads. + */ kill(pid, SIGSTOP); - if (waitpid(pid, NULL, 0) < 0) - err(1, "Unexpected stop in waitpid"); - + for (;;) { + if (waitpid(pid, &status, 0) < 0) + err(1, "Unexpected error in waitpid"); + sig = WIFSTOPPED(status) ? WSTOPSIG(status) : 0; + if (sig == SIGSTOP) + break; + if (sig == SIGTRAP) + sig = 0; + if (ptrace(PT_CONTINUE, pid, (caddr_t)1, sig) < 0) + err(1, "Can not continue for detach"); + } + if (ptrace(PT_DETACH, pid, (caddr_t)1, 0) < 0) err(1, "Can not detach the process"); diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -1945,11 +1945,9 @@ fputs(strsig2(args[sc->offset]), fp); break; case Sigset: { - long sig; sigset_t ss; int i, first; - sig = args[sc->offset]; if (get_struct(pid, args[sc->offset], (void *)&ss, sizeof(ss)) == -1) { print_pointer(fp, args[sc->offset]);