pussuw opened a new pull request, #8486:
URL: https://github.com/apache/nuttx/pull/8486

   ## Summary
   There is an issue where the wrong process exit code is given to the parent 
when a process exits. This happens when the process has pthreads running user 
code i.e. not within a cancel point / system call.
   
   Why does this happen ?
   
   When exit() is called, the following steps are done:
   - group_kill_children(), which tells the children to die via pthread_cancel()
   
   Then, one of two things can happen:
   1. if the child is in a cancel point, it gets scheduled to allow it to leave 
the cancel point and gets destroyed immediately
   2. if the child is not in a cancel point, a "cancel pending" flag is set and 
the child will die when the next cancel point is encountered
   
   So what is the problem here?
   
   The last thread alive dispatches SIGCHLD to the parent, which carries the 
process's exit code. The group head has the only meaningful exit code and this 
is what should be passed. However, in the second case, the group head exits 
before the child, taking the process exit code to its grave. The child that was 
alive will exit next and will pass its "status" to the parent process, but this 
status is not the correct value to pass.
   
   This commit fixes the issue by passing the group head's exit code ALWAYS to 
the parent process.
   ## Impact
   Fixes process exit code, when parent dies before its children die
   ## Testing
   icicle:knsh
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to