Check return value of chdir, and duplicate file descriptors differently.