tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

usr.bin/mail/dotlock.c loop-condition fix



Hello,
counter may exhaust in which case the "foreign semi-unique" lock
is stolen a.k.a. unlink(2)ed.
.. and have a nice weekend!

--steffen
--- dotlock.c.orig	2015-07-04 14:46:47.000000000 +0200
+++ dotlock.c	2015-07-04 14:49:31.000000000 +0200
@@ -80,13 +80,13 @@ create_exclusive(const char *fname)
 	/*
 	 * We try to create the unique filename.
 	 */
-	for (ntries = 0; ntries < 5; ntries++) {
+	for (ntries = 0;; ++ntries) {
 		fd = open(path, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_SYNC, 0);
 		if (fd != -1) {
 			(void)close(fd);
 			break;
 		}
-		else if (errno == EEXIST)
+		else if (errno == EEXIST && ntries < 5)
 			continue;
 		else
 			return -1;


Home | Main Index | Thread Index | Old Index