From: Peter Stephenson <pws@csr.com>
To: zsh-workers <zsh-workers@sunsite.dk>
Subject: Re: cd -s symlink hangs (sometimes?)
Date: Mon, 23 Mar 2009 10:49:28 +0000 [thread overview]
Message-ID: <20090323104928.0c59c30f@news01> (raw)
In-Reply-To: <237967ef0903221605h11983bb4v4eda8d2a1c41a1c9@mail.gmail.com>
On Mon, 23 Mar 2009 00:05:10 +0100
Mikael Magnusson <mikachu@gmail.com> 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 <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
next prev parent reply other threads:[~2009-03-23 10:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-20 21:12 Mikael Magnusson
2009-03-20 22:48 ` Peter Stephenson
2009-03-20 23:15 ` Mikael Magnusson
2009-03-22 12:54 ` Peter Stephenson
2009-03-22 23:05 ` Mikael Magnusson
2009-03-23 10:49 ` Peter Stephenson [this message]
2009-03-23 11:46 ` Mikael Magnusson
2009-03-23 12:27 ` Peter Stephenson
2009-03-24 12:46 ` Peter Stephenson
2009-03-24 15:15 ` Bart Schaefer
2009-03-24 16:02 ` Peter Stephenson
2009-04-06 11:07 ` Mikael Magnusson
2009-04-06 11:13 ` Peter Stephenson
2009-03-23 15:18 ` Bart Schaefer
2009-03-23 15:39 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090323104928.0c59c30f@news01 \
--to=pws@csr.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).