The attached patch should handle this. It takes out the proc_lock and
then updates the process's p_stat, p_waited, and parent's p_nstopchild
with the lock held. It then releases the lock.
In the normal exit case, it reacquires the lock and restores p_stat to
its previous value (which almost certainly is SACTIVE, since that's
the value that do_posix_spawn() set, before dispatching the new lwd
for scheduling).
In the several error cases, we go to a new error-exit code where we
again reacquire proc_lock and restore p_stat and p_nstopchild before
continuing with the rest of the error path.
Note that this change has the effect of restoring p_stat in the error
branch. This should not be an issue, since the error code will very
soon call exit1() where the process will be properly disposed.
Note that I have not tested this patch yet, not even compile-test. I
would appreciate additional eyes to review this.
:)