Ensure PWD is set in process environment
Description
If we don't set PWD in the environment of a shell then it doesn't automatically know what the file path of the current directory is.
The traditional algorithm of walking the parent directories and finding the name of the directory you were just in by if the inode of the directory you were just in matches the inode of the parent directory's contents may make use of the inode value in the directory entry structure returned by readdir
.
In the case where the directory entry is a mount-point the directory entry structure's inode value is incorrect since it refers to the directory under the mount-point.
The traditional way to account for this is to use stat and the st_dev
field to determine whether the directory is a mount-point, however Linux bind mounts may be for different paths on the same device, so the st_dev
fields would be the same but the inodes wouldn't match.
The version of this algorithm in some versions of bash assumes something impossible is going on if it can't find the directory and errors. GLibc will assume it might be a mount-point and retry without trusting the directory entry's inode value.
Setting PWD in the environment bypasses the need to use the faulty algorithm.
Changes proposed in this merge request:
- Set PWD in the environment in bwrap sandboxes.
- Set PWD in the environment in chroot sandboxes.
- Set PWD in the environment in test git commands.
CHANGELOG/Release Notes
- Initial version.