diff --git a/tools/nativeguest/hook/handoff.c b/tools/nativeguest/hook/handoff.c index 495970268b..4887bf2aa6 100644 --- a/tools/nativeguest/hook/handoff.c +++ b/tools/nativeguest/hook/handoff.c @@ -154,10 +154,14 @@ static void ddh_forked_by(pid_t child, pid_t thread) { uint64_t seen = __atomic_load_n(slot, __ATOMIC_ACQUIRE); for (;;) { // A later child given the pid (this one reaped while its fork was being recorded) has - // recorded itself already: its record stays. Start times compared within their 19 bits. - if (seen && ddh_record_child(seen) == child && (seen & 0x80000) && (mine & 0x80000)) { - uint64_t theirs = seen & 0x7ffff, ours = mine & 0x7ffff; - if (theirs != ours && ((theirs - ours) & 0x7ffff) < 0x40000) return; + // recorded itself already: its record stays. It is that child's only while the process that + // has the pid now started when it says; any other record of the pid is an earlier child's. + if (seen && ddh_record_child(seen) == child && (seen & 0x80000) && (mine & 0x80000) && + (seen & 0x7ffff) != (mine & 0x7ffff)) { + saved = errno; + long now = ddh_start_time(child); + errno = saved; + if (now > 0 && ((uint64_t)now & 0x7ffff) == (seen & 0x7ffff)) return; } if (__atomic_compare_exchange_n(slot, &seen, mine, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) return; }