Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Unable to read history on latest Cygwin
- X-seq: zsh-users 14659
- From: Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx>
- To: Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>
- Subject: Re: Unable to read history on latest Cygwin
- Date: Thu, 17 Dec 2009 12:00:25 -0800
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type; bh=agFycr0YTj3C8GPMoLT3caaskbaYfw6Lq7SrNh5tP3E=; b=YNOpKHTMbb6NVLLCyd+erFez2qQH3Yfl/AkeLUd0RWo4j7ef/mgjCACZSsPPSi6vqV Ldaw+DoIZY5mkxcie6b+bk0s17vNzedAgE5MD37rdHa6VtfVf6Sn61ENNGQ0rXA06GiC aKWLPnnwNA8LZeA6L+BPS2nq6HYinDsG+DbnE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=VwsTBUzEMbkf2WH5xKsp0GDSNYVtIujyqqbnXWQo2MjKFgx3R3Pa1IA2jTeMFO4p8y g4XqzTigyYpuCLgcMWWTmgUxGs2Gdu7+bWxW9LjXEOs3noLMA8TkkDu/AiGAdnHfujWn IKaRekm2WMAcCKPB9hcpuo7eJmlOw1iRjSCcI=
- In-reply-to: <733654e30912160754q5e505cabo4a2510b41bf1d892@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1260800369.32429.1350005931@xxxxxxxxxxxxxxxxxxxxxxxxxxx> <733654e30912160754q5e505cabo4a2510b41bf1d892@xxxxxxxxxxxxxx>
- Sender: 4wayned@xxxxxxxxx
On Wed, Dec 16, 2009 at 7:54 AM, Wayne Davison
<4wayned@xxxxxxxxx> wrote:
According to various web docs, symlinks are atomic on NFS, so that might be a good thing to use in general (replacing the use of link()).
Attached is my patch for adding preferential use of a symlink as the locking mechanism. ÂThis should interoperate just fine with a hard-link creating locker, but sadly, will have issues if another locker is using open with O_EXCL. ÂI've made the symlink name "/pid-$PID/host-$HOST" in an attempt to make a create (open) over an existing symlink fail with an error (unless the /pid-$PID dir happens to exist and is writable). ÂWe could try to add O_NOFOLLOW (when available) to the O_EXCL-open as well. ÂHowever, hopefully no system will exist where one zsh locker is trying to use open-locking and another is trying to use a link-locking idiom.
What do you think? ÂDangerous? ÂUseful?
..wayne..
index 86b08bd..81b87c5 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2599,11 +2599,36 @@ lockhistfile(char *fn, int keep_trying)
struct stat sb;
int fd;
char *lockfile;
+#ifdef HAVE_SYMLINK
+ char pidbuf[32], *lnk;
+#else
#ifdef HAVE_LINK
char *tmpfile;
#endif
+#endif
lockfile = bicat(unmeta(fn), ".LOCK");
+#ifdef HAVE_SYMLINK
+ sprintf(pidbuf, "/pid-%ld/host-", (long)mypid);
+ lnk = bicat(pidbuf, getsparam("HOST"));
+ /* We'll abuse fd as our success flag. */
+ while ((fd = symlink(lnk, lockfile)) < 0) {
+ if (errno != EEXIST || !keep_trying)
+ break;
+ if (lstat(lockfile, &sb) < 0) {
+ if (errno == ENOENT)
+ continue;
+ break;
+ }
+ if (time(NULL) - sb.st_mtime < 10)
+ sleep(1);
+ else
+ unlink(lockfile);
+ }
+ if (fd < 0)
+ lockhistct--;
+ free(lnk);
+#else /* not HAVE_SYMLINK */
#ifdef HAVE_LINK
if ((fd = gettempfile(fn, 0, &tmpfile)) >= 0) {
FILE *out = fdopen(fd, "w");
@@ -2660,6 +2685,7 @@ lockhistfile(char *fn, int keep_trying)
close(fd);
}
#endif /* not HAVE_LINK */
+#endif /* not HAVE_SYMLINK */
free(lockfile);
}
index 5693007..262fe5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1169,7 +1169,8 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \
htons ntohs \
regcomp regexec regerror regfree \
gdbm_open getxattr \
- realpath canonicalize_file_name)
+ realpath canonicalize_file_name \
+ symlink)
AC_FUNC_STRCOLL
if test x$enable_cap = xyes; then
Messages sorted by:
Reverse Date,
Date,
Thread,
Author