For one, remove the password cache cleaning, as it no longer is run. For another, skip the fork if uid is already 0. Finally, wrap the check in a try/finally to keep the privileged process more certain in exiting.