bash returns wrong error code when changing to nonexisting directory

Bug #85552 reported by Björn Torkelsson
4
Affects Status Importance Assigned to Milestone
bash (Ubuntu)
Triaged
Low
neelima parakala

Bug Description

Binary package hint: bash

When removing current directory and then doing a cd . bash reports sucess when invoked as /bin/bash but reports failure when invoked as /bin/sh. IMO it should report failure in both cases.

ankpelle[~]$ /bin/bash
ankpelle[~]$ mkdir /scratch/kalle
ankpelle[~]$ cd /scratch/kalle/
ankpelle[kalle]$ rmdir /scratch/kalle
ankpelle[kalle]$ cd .
cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
ankpelle[.]$ echo $?
0
ankpelle[.]$ pwd
/scratch/kalle/.
ankpelle[.]$ exit
exit
sh-3.2$ mkdir /scratch/kalle
sh-3.2$ cd /scratch/kalle/
sh-3.2$ rmdir /scratch/kalle
sh-3.2$ cd .
sh: cd: .: No such file or directory
sh-3.2$ echo $?
1
sh-3.2$ pwd
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
sh-3.2$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2007-02-16 13:33 /bin/sh -> bash
sh-3.2$ exit

Revision history for this message
Chris Rose (chris-vault5) wrote :

Thank you for your bug report. In this instance, cd returns success because it has actually chdir()'d, the problem comes when bash can't realise the path that it is actually in.

You can see discussion of this problem here:

http://groups.google.co.uk/group/gnu.bash.bug/browse_thread/thread/ad71fec768f10fa6/a6dfb11dc2e87403

It isn't clear if it is actually considred a bug or not and if it is, if bash is the cause. I've marked this as needs info because someone with more clue than myself needs to work out where the bug actually lies.

Changed in bash:
status: Unconfirmed → Needs Info
Changed in bash:
assignee: nobody → chris-vault5
importance: Undecided → Low
Revision history for this message
Mika Fischer (zoop) wrote :

I don't think this is the same problem. It should be forwarded upstream. I'll do it next week if noone beats me to it.

Changed in bash:
status: Incomplete → Triaged
Revision history for this message
Rolf Leggewie (r0lf) wrote :

There hasn't been any activity in this ticket for a while. Is this still a problem in Jaunty or Karmic?

Changed in bash (Ubuntu):
status: Triaged → Incomplete
Revision history for this message
Björn Torkelsson (torkel) wrote :

Yes, Karmic shows the exact same behaviour. The only difference is that /bin/sh points to /bin/dash nowdays, however creating a link to /bin/bash named sh shows the same behaviour as the original bug report:

torkel@skruttibangbang:~$ /bin/bash
torkel@skruttibangbang:~$ mkdir /scratch/kalle
torkel@skruttibangbang:~$ cd /scratch/kalle/
torkel@skruttibangbang:/scratch/kalle$ rmdir /scratch/kalle
torkel@skruttibangbang:/scratch/kalle$ cd .
cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
torkel@skruttibangbang:/scratch/kalle/.$ echo $?
0
torkel@skruttibangbang:/scratch/kalle/.$ pwd
/scratch/kalle/.
torkel@skruttibangbang:/scratch/kalle/.$ exit
exit
torkel@skruttibangbang:~$ /bin/sh
$ mkdir /scratch/kalle
$ cd /scratch/kalle/
$ rmdir /scratch/kalle
$ cd .
cd: 4: can't cd to .
$ echo $?
2
$ pwd
/scratch/kalle
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2009-05-20 01:24 /bin/sh -> dash
$ exit
torkel@skruttibangbang:~$ /scratch/sh
sh-4.0$ mkdir /scratch/kalle
sh-4.0$ cd /scratch/kalle/
sh-4.0$ rmdir /scratch/kalle
sh-4.0$ cd .
sh: cd: .: No such file or directory
sh-4.0$ echo $?
1
sh-4.0$ pwd
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
sh-4.0$ ls -l /scratch/sh
lrwxrwxrwx 1 torkel torkel 9 2009-08-28 08:04 /scratch/sh -> /bin/bash
sh-4.0$ exit
exit
torkel@skruttibangbang:~$ bash --version
GNU bash, version 4.0.28(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Rolf Leggewie (r0lf)
Changed in bash (Ubuntu):
assignee: Chris Rose (chris-vault5) → nobody
status: Incomplete → Triaged
Changed in bash (Ubuntu):
assignee: nobody → neelima parakala (lissomlilyneelu)
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.