dup2 calls reversed (hopefully correct now).