From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8871 invoked from network); 24 Mar 2009 16:07:36 -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.4 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; 24 Mar 2009 16:07:36 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 67528 invoked from network); 24 Mar 2009 16:07:31 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 24 Mar 2009 16:07:31 -0000 Received: (qmail 10958 invoked by alias); 24 Mar 2009 16:07:25 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26774 Received: (qmail 10946 invoked from network); 24 Mar 2009 16:07:25 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 24 Mar 2009 16:07:25 -0000 Received: from cluster-d.mailcontrol.com (cluster-d.mailcontrol.com [85.115.60.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id CE5F980590EB for ; Tue, 24 Mar 2009 17:07:16 +0100 (CET) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly16d.srv.mailcontrol.com (MailControl) with ESMTP id n2OG6R3P024641 for ; Tue, 24 Mar 2009 16:07:14 GMT Received: from news01 ([10.99.50.25]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Tue, 24 Mar 2009 16:02:15 +0000 Date: Tue, 24 Mar 2009 16:02:15 +0000 From: Peter Stephenson To: zsh-workers Subject: Re: cd -s symlink hangs (sometimes?) Message-ID: <20090324160215.21c7236b@news01> In-Reply-To: <090324081538.ZM6216@torch.brasslantern.com> References: <237967ef0903201412h2a7b99c9ya5101509a3972313@mail.gmail.com> <20090320224856.73dae001@pws-pc> <237967ef0903201615x72769fe4va86273c3fa07cb2e@mail.gmail.com> <20090322125410.66a9d294@pws-pc> <237967ef0903221605h11983bb4v4eda8d2a1c41a1c9@mail.gmail.com> <20090323104928.0c59c30f@news01> <237967ef0903230446u6810c06cs511fddcc21fd2a8a@mail.gmail.com> <20090323122714.3373526a@news01> <20090324124612.26017e86@news01> <090324081538.ZM6216@torch.brasslantern.com> Organization: CSR X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 24 Mar 2009 16:02:15.0877 (UTC) FILETIME=[E6CA6F50:01C9AC99] X-Scanned-By: MailControl A_08_51_00 (www.mailcontrol.com) on 10.68.0.126 X-Virus-Scanned: ClamAV 0.92.1/9159/Tue Mar 24 15:59:06 2009 on bifrost X-Virus-Status: Clean On Tue, 24 Mar 2009 08:15:38 -0700 Bart Schaefer wrote: > On Mar 24, 12:46pm, Peter Stephenson wrote: > } > } For the diagnostics and pwd, I've just borrowed what the recursive > } handling in zsh/files does, which is cd to /, set pwd consistently, > } and report the error. > > This is calling zerr(), which sets errflag, which means a script that > encounters this problem would abort at that point, correct? (That > seems to be the behavior in a few simple tests I did.) Yes, this seems serious enough. > I'd be worried that if the only error is that chdir returns nonzero, > changing into the root directory creates a security problem (what if > the user is privileged and the next command is "rm -rf *" etc.). > > Maybe it would be better to first attempt chdir($HOME) and only fall > back on "/" if that also fails. That makes sense, that is what "cd" on its own does, after all. > Also, should $OLDPWD be getting updated? > I'm undecided on that. We did change directories, even though not to the > desired destination. Codewise, we're a little bit too low down to deal with this easily and correctly. I think the only consistent way of doing this would be to call cd_new_pd(), which we currently only do on a successful cd or pushd. Anything else looks to me like an inconsistent half measure. We would then be executing chpwd (etc.); this might be correct (fixing up a terminal header, for example), or it might do stuff the user didn't want. It's hard to decide. Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.219 diff -u -r1.219 utils.c --- Src/utils.c 24 Mar 2009 12:52:07 -0000 1.219 +++ Src/utils.c 24 Mar 2009 15:58:30 -0000 @@ -5493,16 +5493,30 @@ } if (restoredir(d)) { int restoreerr = errno; + int i; /* * Failed to restore the directory. * Just be definite, cd to root and report the result. */ - zsfree(pwd); - pwd = ztrdup("/"); - if (chdir(pwd) < 0) + for (i = 0; i < 2; i++) { + const char *cdest; + if (i) + cdest = "/"; + else { + if (!home) + continue; + cdest = home; + } + zsfree(pwd); + pwd = ztrdup(cdest); + if (chdir(pwd) == 0) + break; + } + if (i == 2) zerr("lost current directory, failed to cd to /: %e", errno); else - zerr("lost current directory: %e: changed to /", restoreerr); + zerr("lost current directory: %e: changed to `%s'", restoreerr, + pwd); if (d == &ds) zsfree(ds.dirname); #ifdef HAVE_FCHDIR -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070