zsh's pwd gets confused with $PWD unset in mounted dir (bind/nfs)

Bug #312156 reported by AlainKnaff
4
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/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 "."

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

Revision history for this message
Jay Strict (jay-strict) wrote :

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%

Changed in zsh (Ubuntu):
status: New → Confirmed
Revision history for this message
Daniel Hahler (blueyed) wrote :

I can confirm this using zsh 4.3.17 in Ubuntu Precise:
mkdir /tmp/foo
mkdir /tmp/bar
sudo mount -o bind /tmp/foo /tmp/bar
cd /tmp/bar
unset PWD
zsh
pwd

=> /tmp/foo

Changed in zsh (Ubuntu):
importance: Undecided → Low
status: Confirmed → Triaged
description: updated
summary: - zsh's pwd gets confused by bind mounts
+ zsh's pwd gets confused with $PWD unset in mounted dir (bind/nfs)
Revision history for this message
Axel Beckert (xtaran) wrote :

Seems still the case with zsh 5.0.2.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.