Dup FDs on startup rather than closing them later

Together with the previous commits this does fix #3823