mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-11-01 06:20:55 +01:00
+ Needed to call unmeta() in a few spots that used the HISTFILE name.
+ The non-HAVE_LINK code in lockhistfile() was broken in a number of ways. + Added an extra unlink() call to the HAVE_LINK code in lockhistfile() since (Linix at least says that) O_EXCL over NFS is broken.
This commit is contained in:
parent
d13f6631d7
commit
2b602a93e6
1 changed files with 37 additions and 21 deletions
58
Src/hist.c
58
Src/hist.c
|
|
@ -1695,7 +1695,7 @@ readhistfile(char *fn, int err, int readflags)
|
|||
if (!fn && !(fn = getsparam("HISTFILE")))
|
||||
return;
|
||||
if (readflags & HFILE_FAST) {
|
||||
if (stat(fn, &sb) < 0
|
||||
if (stat(unmeta(fn), &sb) < 0
|
||||
|| (lasthist.fsiz == sb.st_size && lasthist.mtim == sb.st_mtime)
|
||||
|| !lockhistfile(fn, 0))
|
||||
return;
|
||||
|
|
@ -1980,17 +1980,23 @@ lockhistfile(char *fn, int keep_trying)
|
|||
return 0;
|
||||
if (!lockhistct++) {
|
||||
struct stat sb;
|
||||
int fd, len = strlen(fn);
|
||||
char *tmpfile, *lockfile;
|
||||
int fd, len;
|
||||
char *lockfile;
|
||||
#ifdef HAVE_LINK
|
||||
char *tmpfile;
|
||||
#endif
|
||||
|
||||
fn = unmeta(fn);
|
||||
len = strlen(fn);
|
||||
lockfile = zalloc(len + 5 + 1);
|
||||
sprintf(lockfile, "%s.LOCK", fn);
|
||||
#ifdef HAVE_LINK
|
||||
tmpfile = zalloc(len + 10 + 1);
|
||||
sprintf(tmpfile, "%s.%ld", fn, (long)mypid);
|
||||
if ((fd = open(tmpfile, O_RDWR|O_CREAT|O_EXCL, 0644)) >= 0) {
|
||||
write(fd, "0\n", 2);
|
||||
unlink(tmpfile); /* NFS's O_EXCL is often broken... */
|
||||
if ((fd = open(tmpfile, O_WRONLY|O_CREAT|O_EXCL, 0644)) >= 0) {
|
||||
write(fd, tmpfile+len+1, strlen(tmpfile+len+1));
|
||||
close(fd);
|
||||
lockfile = zalloc(len + 5 + 1);
|
||||
sprintf(lockfile, "%s.LOCK", fn);
|
||||
while (link(tmpfile, lockfile) < 0) {
|
||||
if (stat(lockfile, &sb) < 0) {
|
||||
if (errno == ENOENT)
|
||||
|
|
@ -2006,25 +2012,33 @@ lockhistfile(char *fn, int keep_trying)
|
|||
lockhistct--;
|
||||
break;
|
||||
}
|
||||
free(lockfile);
|
||||
unlink(tmpfile);
|
||||
}
|
||||
unlink(tmpfile);
|
||||
free(tmpfile);
|
||||
#else /* not HAVE_LINK */
|
||||
lockfile = zalloc(len + 5 + 1);
|
||||
sprintf(lockfile, "%s.LOCK", fn);
|
||||
while ((fd = open(lockfile, O_CREAT|O_EXCL, 0644)) < 0) {
|
||||
if (errno == EEXIST) continue;
|
||||
else if (keep_trying) {
|
||||
if (time(NULL) - sb.st_mtime < 10)
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
lockhistct--;
|
||||
while ((fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0) {
|
||||
if (errno != EEXIST || !keep_trying)
|
||||
break;
|
||||
if (stat(lockfile, &sb) < 0) {
|
||||
if (errno == ENOENT)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
if (time(NULL) - sb.st_mtime < 10)
|
||||
sleep(1);
|
||||
else
|
||||
unlink(lockfile);
|
||||
}
|
||||
if (fd < 0)
|
||||
lockhistct--;
|
||||
else {
|
||||
char buf[16];
|
||||
sprintf(buf, "%ld", (long)mypid);
|
||||
write(fd, buf, strlen(buf));
|
||||
close(fd);
|
||||
}
|
||||
#endif /* not HAVE_LINK */
|
||||
free(lockfile);
|
||||
#endif /* HAVE_LINK */
|
||||
}
|
||||
return ct != lockhistct;
|
||||
}
|
||||
|
|
@ -2044,7 +2058,9 @@ unlockhistfile(char *fn)
|
|||
lockhistct = 0;
|
||||
}
|
||||
else {
|
||||
char *lockfile = zalloc(strlen(fn) + 5 + 1);
|
||||
char *lockfile;
|
||||
fn = unmeta(fn);
|
||||
lockfile = zalloc(strlen(fn) + 5 + 1);
|
||||
sprintf(lockfile, "%s.LOCK", fn);
|
||||
unlink(lockfile);
|
||||
free(lockfile);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue