From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25018 invoked from network); 23 Mar 2009 15:18:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 23 Mar 2009 15:18:41 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 57015 invoked from network); 23 Mar 2009 15:18:35 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 23 Mar 2009 15:18:35 -0000 Received: (qmail 2049 invoked by alias); 23 Mar 2009 15:18:29 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26770 Received: (qmail 2039 invoked from network); 23 Mar 2009 15:18:29 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 23 Mar 2009 15:18:29 -0000 Received: from vms173017pub.verizon.net (vms173017pub.verizon.net [206.46.173.17]) by bifrost.dotsrc.org (Postfix) with ESMTP id C7D5480590EB for ; Mon, 23 Mar 2009 16:18:24 +0100 (CET) Received: from torch.brasslantern.com ([96.249.201.13]) by vms173017.mailsrvcs.net (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008; 32bit)) with ESMTPA id <0KGY00D7TT6BLG2E@vms173017.mailsrvcs.net> for zsh-workers@sunsite.dk; Mon, 23 Mar 2009 10:18:12 -0500 (CDT) Received: from torch.brasslantern.com (localhost.localdomain [127.0.0.1]) by torch.brasslantern.com (8.13.1/8.13.1) with ESMTP id n2NFIAdj004299 for ; Mon, 23 Mar 2009 08:18:10 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id n2NFI9D3004298 for zsh-workers@sunsite.dk; Mon, 23 Mar 2009 08:18:09 -0700 From: Bart Schaefer Message-id: <090323081809.ZM4297@torch.brasslantern.com> Date: Mon, 23 Mar 2009 08:18:09 -0700 In-reply-to: <20090322125410.66a9d294@pws-pc> Comments: In reply to Peter Stephenson "Re: cd -s symlink hangs (sometimes?)" (Mar 22, 12:54pm) References: <237967ef0903201412h2a7b99c9ya5101509a3972313@mail.gmail.com> <20090320224856.73dae001@pws-pc> <237967ef0903201615x72769fe4va86273c3fa07cb2e@mail.gmail.com> <20090322125410.66a9d294@pws-pc> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers Subject: Re: cd -s symlink hangs (sometimes?) MIME-version: 1.0 Content-type: text/plain; charset=us-ascii X-Virus-Scanned: ClamAV 0.92.1/9152/Mon Mar 23 14:15:24 2009 on bifrost X-Virus-Status: Clean On Mar 22, 12:54pm, Peter Stephenson wrote: } } The problem is still the code I was scratching my head over before: } } #ifdef HAVE_FCHDIR } if (d->dirfd < 0 && (d->dirfd = open(".", O_RDONLY | O_NOCTTY)) < 0 && } zgetdir(d) && *d->dirname != '/') } d->dirfd = open("..", O_RDONLY | O_NOCTTY); } #endif } } It's now being executed, but we can't open "." any more. So it's } failing to save a fchdir-able directory for restoring, so after the "cd } -s" fails we end up still in / again. I did a quick search of the zsh-workers archives and that code appears to predate the earliest messages from the mailing list that are there, or at least to predate the habit of mailing patches to the lists. So if it was hacked in without fixing the rest of the structure, it was hacked in a very long time ago. Anyway, as best I can tell the reason for the open("..") is to cause an error to be returned from restoredir() later. At the code above, if open(".") fails but zgetdir() succeeds, we can stat(".") but not read it. So the code attempts to arrange that restoredir() will cd into a directory that we CAN read (".." in this case), but leaves mismatched ino,dev information in the dirsave struct so restoredir() will return nonzero, causing lchdir() to return -2. In the course of looking at this I think I've spotted another problem, which possibly only affects filesystems where a double slash at the root means something different (mainly Cygwin at this point). Have a look at zchdir() and consider the consequences of passing it a file name consisting entirely of "/" characters repeated PATH_MAX+N times.