zsh's pwd gets confused with $PWD unset in mounted dir (bind/nfs)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
zsh (Ubuntu) |
Triaged
|
Low
|
Unassigned |
Bug Description
When starting zsh in a subdirectory mounted using a bind mount, without the PWD variable being set, zsh becomes confused, and is unable to determine its working directory. Moreover, during the attempt to find out its working directory, it moves to a different place.
In order to test 32-bit software on my 64-bit system, I've set up a chroot under /home/chroot/
mount -o bind /home /home/chroot/
When I cd into any subdirectory of a subdirectory of /home/chroot/
Other shells, such as bash, handle this situation just fine.
In the "wild" this situation happens when using schroot to execute a zsh in my 32 bit chroot environment (because by default, schroot unsets PWD before calling the shell). However, as shown above, the reason for the behavior is unrelated to the chroot system call, but can be reproduced with bind mounts alone.
I suspect that the reason for this bug is some bogus "optimization" on how zsh detects mountpoints. Rather than assuming a mountpoint as soon as none of the inode numbers of the subdirectories of the parent match that of the current directory, zsh relies solely on a comparison of the device number of parent and current. However, in case of a bind mount both may match, even though a mountpoint is present.
-------
> lsb_release -rd
Description: Ubuntu 8.04.1
Release: 8.04
> apt-cache policy zsh
zsh:
Installé : 4.3.4-24ubuntu1
Candidat : 4.3.4-24ubuntu1
Table de version :
*** 4.3.4-24ubuntu1 0
500 http://
100 /var/lib/
How to reproduce:
-------
mkdir -p /home/alain/tmp
mkdir -p /home /home/chroot/
mount -o bind /home /home/chroot/
cd /home /home/chroot/
unset PWD
zsh
What I expect to happen:
-------
zsh's current dir should be /home/chroot/
What happened instead:
-------
zsh's current dir is /home/chroot/
TEST CASE:
mkdir /tmp/foo
mkdir /tmp/bar
sudo mount -o bind /tmp/foo /tmp/bar
cd /tmp/bar
unset PWD
zsh
pwd
=> /tmp/foo
But should be /tmp/bar
I can confirm this bug is still active in Jaunty.
I use nautilus- open-terminal to open a terminal in an NFS share and zsh is my default shell.
It is annoying that zsh does not open in the directory which is active in the nautilus window, but instead it opens in a directory above.
How to reproduce: ------- ------- -------
-------
newton% chsh -s /bin/zsh
Password:
newton% nautilus
newton%
[Open a proper subdirectory of an NFS mount! Right-click and select "Open In Terminal"]
newton% pwd
.
newton%