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/ubuntu-8.04-i386 under which I've mounted the real home using mount -o bind:
mount -o bind /home /home/chroot/ubuntu-8.04-i386/home
When I cd into any subdirectory of a subdirectory of /home/chroot/ubuntu-8.04-i386/home , unset PWD, and start zsh, zsh becomes confused as soon as its pwd algorithm crosses the bind mountpoint.
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.
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/ ubuntu- 8.04-i386 under which I've mounted the real home using mount -o bind:
mount -o bind /home /home/chroot/ ubuntu- 8.04-i386/ home
When I cd into any subdirectory of a subdirectory of /home/chroot/ ubuntu- 8.04-i386/ home , unset PWD, and start zsh, zsh becomes confused as soon as its pwd algorithm crosses the bind mountpoint.
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.
------- ------- ------- ------- - be.archive. ubuntu. com hardy/main Packages dpkg/status
> 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: ------- ------- ------- ubuntu- 8.04-i386/ home ubuntu- 8.04-i386/ home ubuntu- 8.04-i386/ home/alain/ tmp
-------
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/ ubuntu- 8.0.4-i386/ home/alain/ tmp , and pwd should show same
What happened instead: ------- ------- ------- ------- --
-------
zsh's current dir is /home/chroot/ ubuntu- 8.0.4-i386/ home , and pwd shows "."