fcntl and dup tidy up