about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorWayne Davison <wayned@users.sourceforge.net>2004-05-11 21:45:36 +0000
committerWayne Davison <wayned@users.sourceforge.net>2004-05-11 21:45:36 +0000
commit1ec2b5c096e4a7a47bff2f65fe3dce104a063dec (patch)
tree3b4ef8881171659880c0e802e7e408ba9382ed3c /Src
parentc00fdaa3f09ab95310ae87251d8dcc7507f45a18 (diff)
downloadzsh-1ec2b5c096e4a7a47bff2f65fe3dce104a063dec.tar.gz
zsh-1ec2b5c096e4a7a47bff2f65fe3dce104a063dec.tar.xz
zsh-1ec2b5c096e4a7a47bff2f65fe3dce104a063dec.zip
Fix the potential for an infinite loop in lockhistfile() if the
link() calls fails for some other reason than EEXIST.
Diffstat (limited to 'Src')
-rw-r--r--Src/hist.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/Src/hist.c b/Src/hist.c
index 0e0c4be98..e0b0475fb 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2139,11 +2139,13 @@ lockhistfile(char *fn, int keep_trying)
 	    write(fd, tmpfile+len+1, strlen(tmpfile+len+1));
 	    close(fd);
 	    while (link(tmpfile, lockfile) < 0) {
-		if (stat(lockfile, &sb) < 0) {
+		if (errno != EEXIST || !keep_trying)
+		    ;
+		else if (stat(lockfile, &sb) < 0) {
 		    if (errno == ENOENT)
 			continue;
 		}
-		else if (keep_trying) {
+		else {
 		    if (time(NULL) - sb.st_mtime < 10)
 			sleep(1);
 		    else