Fix calls related to opening files.

They failed to align certain process state before being called,
including the the cwd.