From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13163 invoked from network); 23 Mar 2009 10:55:20 -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; 23 Mar 2009 10:55:20 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 87375 invoked from network); 23 Mar 2009 10:55:12 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 23 Mar 2009 10:55:12 -0000 Received: (qmail 4510 invoked by alias); 23 Mar 2009 10:55:06 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26767 Received: (qmail 4493 invoked from network); 23 Mar 2009 10:55:06 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 23 Mar 2009 10:55:06 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [208.87.233.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id D4C6880590EB for ; Mon, 23 Mar 2009 11:54:58 +0100 (CET) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly24g.srv.mailcontrol.com (MailControl) with ESMTP id n2NAseF7008647 for ; Mon, 23 Mar 2009 10:54:56 GMT Received: from news01 ([10.99.11.74]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Mon, 23 Mar 2009 10:49:33 +0000 Date: Mon, 23 Mar 2009 10:49:28 +0000 From: Peter Stephenson To: zsh-workers Subject: Re: cd -s symlink hangs (sometimes?) Message-ID: <20090323104928.0c59c30f@news01> In-Reply-To: <237967ef0903221605h11983bb4v4eda8d2a1c41a1c9@mail.gmail.com> References: <237967ef0903201412h2a7b99c9ya5101509a3972313@mail.gmail.com> <20090320224856.73dae001@pws-pc> <237967ef0903201615x72769fe4va86273c3fa07cb2e@mail.gmail.com> <20090322125410.66a9d294@pws-pc> <237967ef0903221605h11983bb4v4eda8d2a1c41a1c9@mail.gmail.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: 23 Mar 2009 10:49:33.0680 (UTC) FILETIME=[0D3C9F00:01C9ABA5] X-Scanned-By: MailControl A_08_51_00 (www.mailcontrol.com) on 10.71.0.134 X-Virus-Scanned: ClamAV 0.92.1/9151/Mon Mar 23 06:23:57 2009 on bifrost X-Virus-Status: Clean On Mon, 23 Mar 2009 00:05:10 +0100 Mikael Magnusson wrote: > I just noticed (ls -l /proc/$$/fd) that with this last commit, zsh now keeps > all my old directories open, even when I don't use -s or anything special. Lucky you noticed. This is more overload-things-in-a-complicated-fashion-without-documentation fallout. The following should be safer, although the bug you noticed was, I think, just because we didn't need to open the directory at all if allowed to follow links because zchdir doesn't use restoredir(). So close_dir may be redundant, but it's hard to tell. Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.216 diff -u -r1.216 utils.c --- Src/utils.c 20 Mar 2009 22:52:56 -0000 1.216 +++ Src/utils.c 23 Mar 2009 10:46:11 -0000 @@ -5374,6 +5374,9 @@ int err; struct stat st2; #endif +#ifdef HAVE_FCHDIR + int close_dir = 0; +#endif if (!d) { ds.ino = ds.dev = 0; @@ -5400,11 +5403,6 @@ d->ino = st1.st_ino; } } -#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 #ifdef HAVE_LSTAT if (!hard) @@ -5420,7 +5418,16 @@ } return zchdir((char *) path); } + #ifdef HAVE_LSTAT +#ifdef HAVE_FCHDIR + if (d->dirfd < 0) { + close_dir = 1; + if ((d->dirfd = open(".", O_RDONLY | O_NOCTTY) < 0) && + zgetdir(d) && *d->dirname != '/') + d->dirfd = open("..", O_RDONLY | O_NOCTTY); + } +#endif if (*path == '/') if (chdir("/") < 0) zwarn("failed to chdir(/): %e", errno); @@ -5428,12 +5435,16 @@ while(*path == '/') path++; if(!*path) { - if (d == &ds) { + if (d == &ds) zsfree(ds.dirname); - if (ds.dirfd >=0) - close(ds.dirfd); - } else + else d->level = level; +#ifdef HAVE_FCHDIR + if (d->dirfd >=0 && close_dir) { + close(d->dirfd); + d->dirfd = -1; + } +#endif return 0; } for(pptr = path; *++pptr && *pptr != '/'; ) ; @@ -5468,19 +5479,25 @@ } } if (restoredir(d)) { - if (d == &ds) { + if (d == &ds) zsfree(ds.dirname); - if (ds.dirfd >=0) - close(ds.dirfd); +#ifdef HAVE_FCHDIR + if (d->dirfd >=0 && close_dir) { + close(d->dirfd); + d->dirfd = -1; } +#endif errno = err; return -2; } - if (d == &ds) { + if (d == &ds) zsfree(ds.dirname); - if (ds.dirfd >=0) - close(ds.dirfd); +#ifdef HAVE_FCHDIR + if (d->dirfd >=0 && close_dir) { + close(d->dirfd); + d->dirfd = -1; } +#endif errno = err; return -1; #endif /* HAVE_LSTAT */ -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070