Comment 0 for bug 312156

Revision history for this message
AlainKnaff (kubuntu-misc) wrote : zsh's pwd gets confused by bind mounts

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.

-----------------------------
> 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://be.archive.ubuntu.com hardy/main Packages
        100 /var/lib/dpkg/status

How to reproduce:
----------------------------
mkdir -p /home/alain/tmp
mkdir -p /home /home/chroot/ubuntu-8.04-i386/home
mount -o bind /home /home/chroot/ubuntu-8.04-i386/home
cd /home /home/chroot/ubuntu-8.04-i386/home/alain/tmp
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 "."