Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [4.2.0] Src/hist.c:lockhistfile() endless loop



On Fri, May 07, 2004 at 12:35:15PM +0200, KELEMEN Peter wrote:
> This looks like an endless loop if
>  1) link() fails, and
>  2) stat() returns -ENOENT.

Seems to me that the attached change would avoid the infinite loop in
the failure case you cite.

..wayne..
--- Src/hist.c	29 Oct 2003 19:17:30 -0000	1.47
+++ Src/hist.c	7 May 2004 15:39:44 -0000
@@ -2139,7 +2139,9 @@ 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)
+		    ;
+		else if (stat(lockfile, &sb) < 0) {
 		    if (errno == ENOENT)
 			continue;
 		}


Messages sorted by: Reverse Date, Date, Thread, Author