about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2014-09-06 22:10:30 -0700
committerBarton E. Schaefer <schaefer@zsh.org>2014-09-06 22:10:30 -0700
commit4414e54ea7ffe50acca851c11c2ef49dc867c55d (patch)
tree323cccfdc3faa0956082432f54947513d82efe5a
parentc61a927d1d156731d9e21c714dfea9585163c556 (diff)
downloadzsh-4414e54ea7ffe50acca851c11c2ef49dc867c55d.tar.gz
zsh-4414e54ea7ffe50acca851c11c2ef49dc867c55d.tar.xz
zsh-4414e54ea7ffe50acca851c11c2ef49dc867c55d.zip
33116: followup to 32580 to prevent double-locking with shared or incremental history
-rw-r--r--ChangeLog5
-rw-r--r--Src/hist.c14
2 files changed, 13 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 34b52e2cb..9556bef8b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-09-06  Barton E. Schaefer  <schaefer@zsh.org>
+
+	* 33116: Src/hist.c: followup to 32580 to prevent double-locking
+	with shared or incremental history
+
 2014-08-21  Mikael Magnusson  <mikachu@gmail.com>
 
 	* 33061: Completion/Zsh/Command/_setopt,
diff --git a/Src/hist.c b/Src/hist.c
index 770d559b1..d29a65afe 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2490,6 +2490,9 @@ flockhistfile(char *fn, int keep_trying)
     struct flock lck;
     int ctr = keep_trying ? 9 : 0;
 
+    if (flock_fd >= 0)
+	return 0; /* already locked */
+
     if ((flock_fd = open(unmeta(fn), O_RDWR | O_NOCTTY)) < 0)
 	return errno == ENOENT ? 0 : 2; /* "successfully" locked missing file */
 
@@ -2768,12 +2771,6 @@ lockhistfile(char *fn, int keep_trying)
     if (!fn && !(fn = getsparam("HISTFILE")))
 	return 1;
 
-#ifdef HAVE_FCNTL_H
-    if (isset(HISTFCNTLLOCK) && flock_fd < 0) {
-	return flockhistfile(fn, keep_trying);
-    }
-#endif
-
     if (!lockhistct++) {
 	struct stat sb;
 	int fd;
@@ -2786,6 +2783,11 @@ lockhistfile(char *fn, int keep_trying)
 # endif
 #endif
 
+#ifdef HAVE_FCNTL_H
+	if (isset(HISTFCNTLLOCK))
+	    return flockhistfile(fn, keep_trying);
+#endif
+
 	lockfile = bicat(unmeta(fn), ".LOCK");
 	/* NOTE: only use symlink locking on a link()-having host in order to
 	 * avoid a change from open()-based locking to symlink()-based. */