Garber, Neal wrote:
While reviewing rad_fork, as part of an enhancement I’m working on, I found something questionable.
Most of that code is pretty bad, unfortunately.
After the call to fork, it tests if child_pid != 0 (to see if the parent is the process executing, I presume). If true, then, the child_pid is added to the thread pool and the thread pool mutex is unlocked. However, if the fork failed, -1 is returned (and stored in child_pid), which I believe will then be added to the thread pool (because -1 != 0 and there isn’t an explicit test for fork success/failure). Shouldn’t there be a test for fork success (child_pid > 0) before adding to the thread pool?
Yes.
Perhaps this isn’t a big deal because fork probably doesn’t fail that often. But, it isn’t clear to me what would happen in reap_children when it calls waitpid with -1 as this tells waitpid to return status for any child.
Am I missing something? If not, and you want me to submit a bug report with the minor code change, let me know..
No, just send a patch to the list. Alan DeKok. -- http://deployingradius.com - The web site of the book http://deployingradius.com/blog/ - The blog