From bef9803aba5a5a6552528a848fd0c65f1e6e0948 Mon Sep 17 00:00:00 2001 From: Simon Sobisch Date: Thu, 22 Jul 2021 15:19:12 +0200 Subject: [PATCH] handle plain exit for tasks fixes #2627, #2640 --- src/Task.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Task.cc b/src/Task.cc index d843905c138..10be3a4ee6c 100644 --- a/src/Task.cc +++ b/src/Task.cc @@ -136,17 +136,22 @@ void Task::wait_exit() { * it as an indication that the task has execed. */ while (true) { - int ret = waitid(P_PID, tid, &info, WSTOPPED | WNOWAIT); + int ret = waitid(P_PID, tid, &info, WEXITED | WSTOPPED | WNOWAIT); if (ret == 0) { ASSERT(this, info.si_pid == tid) << "Expected " << tid << " got " << info.si_pid; - if (WaitStatus(info).ptrace_event() == PTRACE_EVENT_EXIT) { + int event = WaitStatus(info).ptrace_event(); + if (event == 0) { // PTRACE_EVENT_STOP + // already finished + break; + } + if (event == PTRACE_EVENT_EXIT) { // It's possible that the earlier exit event was synthetic, in which // case we're only now catching up to the real process exit. In that // case, just ask the process to actually exit. (TODO: We may want to // catch this earlier). return proceed_to_exit(true); } - ASSERT(this, WaitStatus(info).ptrace_event() == PTRACE_EVENT_EXEC) + ASSERT(this, event == PTRACE_EVENT_EXEC) << "Expected PTRACE_EVENT_EXEC, got " << WaitStatus(info); // The kernel will do the reaping for us in this case was_reaped = true;