Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Jan 2008 21:40:54 GMT
From:      Juli Mallett <juli@clockworksquid.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/120128: __getcwd erroneously returning ENOENT
Message-ID:  <200801292140.m0TLesbt083061@www.freebsd.org>
Resent-Message-ID: <200801292150.m0TLo11Q089395@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         120128
>Category:       kern
>Synopsis:       __getcwd erroneously returning ENOENT
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 29 21:50:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Juli Mallett
>Release:        8.0-CURRENT, kern.osreldate: 800008
>Organization:
>Environment:
FreeBSD alala.evergreen.edu 8.0-CURRENT FreeBSD 8.0-CURRENT #7: Tue Jan  8 16:03:13 PST 2008     root@alala.evergreen.edu:/usr/obj/usr/src/sys/ALALA  amd64

>Description:
When removing subdirectories, __getcwd is sometimes falsely returning ENOENT, and continues to do so until pwd -L is invoked (it is the stat($PWD) that fixes the problem, presumably this is updating some cached information somewhere?) in a specific configuration (with a few edge-cases).  This only occurs with tcsh for me, not sh, because the sh builtin compensates for the problem.

^_^ (mallettj@alala:~)267% cd pwd
^_^ (mallettj@alala:~/pwd)268% mkdir foo ; cd foo ; mkdir bar ; rm -rf bar ; pwd -P ; cd .. ; rm -rf foo
pwd: .: Permission denied
^_^ (mallettj@alala:~/pwd)269% mkdir foo ; cd foo ; mkdir bar ; rm -rf bar ; pwd -L ; cd .. ; rm -rf foo
/home/mallettj/pwd/foo
^_^ (mallettj@alala:~/pwd)270% mkdir foo ; cd foo ; mkdir bar ; rm -rf bar ; ~/pwd/pwd -P ; cd .. ; rm -rf foo
/data/home/mallettj/pwd/foo
^_^ (mallettj@alala:~/pwd)271% ls -lartd .
drwxr-xr-x  3 mallettj  mallettj  512 Jan 29 15:38 .
^_^ (mallettj@alala:~/pwd)272% pwd -L
/home/mallettj/pwd
^_^ (mallettj@alala:~/pwd)273% pwd -P
/data/home/mallettj/pwd
^_^ (mallettj@alala:~/pwd)274% ls -lartd /data
drwxr-xr-x  8 root  wheel  512 Jul  5  2007 /data
^_^ (mallettj@alala:~/pwd)275% ls -lartd /data/home
drwx--x--x  9 root  wheel  512 Jan 23 19:00 /data/home
^_^ (mallettj@alala:~/pwd)276% ls -lartd /data/home/mallettj
drwxr-xr-x  13 mallettj  mallettj  1024 Jan 29 15:34 /data/home/mallettj
^_^ (mallettj@alala:~/pwd)277% ls -lartd /data/home/mallettj/pwd
drwxr-xr-x  3 mallettj  mallettj  512 Jan 29 15:38 /data/home/mallettj/pwd
^_^ (mallettj@alala:~/pwd)278% ls -lartd /home
lrwxr-xr-x  1 root  wheel  10 Jun 21  2007 /home -> /data/home
^_^ (mallettj@alala:~/pwd)279% cvs diff -u pwd.c
socket: Protocol not supported
Index: pwd.c
===================================================================
RCS file: /home/ncvs/src/bin/pwd/pwd.c,v
retrieving revision 1.25
diff -u -r1.25 pwd.c
--- pwd.c       9 Feb 2005 17:37:38 -0000       1.25
+++ pwd.c       29 Jan 2008 21:39:47 -0000
@@ -84,6 +84,8 @@
         * If we're trying to find the logical current directory and that
         * fails, behave as if -P was specified.
         */
+       struct stat phy;
+       stat(getenv("PWD"), &phy);
        if ((!physical && (p = getcwd_logical()) != NULL) ||
            (p = getcwd(NULL, 0)) != NULL)
                printf("%s\n", p);


>How-To-Repeat:
tcsh -c 'mkdir foo ; cd foo ; mkdir bar ; rm -rf bar ; pwd -P ; cd .. ; rm -rf foo'
>Fix:
Unlikely to have time to dig in to the kernel to figure out the root cause.  Want to stress that the patch in the full description (obviously) is not a solution, should someone stumble over this bug and think it is.  This affects all callers of getcwd, including my shell:

^_^ (mallettj@alala:~/pwd)286% tcsh -c 'mkdir foo ; cd foo ; mkdir bar ; rm -rf bar ; pwd -P ; cd .. ; rm -rf foo'
tcsh: Permission denied
tcsh: Trying to start from "/home/mallettj"
pwd: .: Permission denied
^_^ (mallettj@alala:~/pwd)287% pwd -L
/home/mallettj/pwd
^_^ (mallettj@alala:~/pwd)288% tcsh -c 'mkdir foo ; cd foo ; mkdir bar ; rm -rf bar ; pwd -P ; cd .. ; rm -rf foo'
pwd: .: Permission denied



>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801292140.m0TLesbt083061>