SafeChdir all the things for thread safety