Comment 14 for bug 264711

Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :

I think the fix is even easier than using state flags. At the point we get trap the fork, one of the two following is true:

 - the child process does not yet fully exist and trapping its initial SIGSTOP has yet to happen

 - the child process already exists, and we've missed its initial SIGSTOP

In the former case, we don't need to do anything; in the latter case we need to call job_process_trace_new_child() for the process.

But that's easy; we just try and call ptrace() on the new pid, if it returns with an error we can assume that the process doesn't exist yet, and return. If ptrace() succeeds, we just fall out of the bottom of job_process_trace_fork() into job_process_trace_new_child() and handle the already missed case.

The patch is just to add the following to the bottom of job_process_trace_fork ()

    if (ptrace (PTRACE_SET_OPTIONS, job->pid[process], NULL, 0) < 0))
            return;

    job_process_trace_new_child (job, process);