about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDuncan Overbruck <mail@duncano.de>2021-03-01 00:45:04 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-03-13 16:27:55 +0100
commit8cf40887c7b68f0772a46080fb265e67c7f43b36 (patch)
treeb486025699f72f1dbe8b5edf91e944d03861a350
parent1d402f5fbbfd74be8369765ed8b4d8f664ba4996 (diff)
downloadnq-8cf40887c7b68f0772a46080fb265e67c7f43b36.tar.gz
nq-8cf40887c7b68f0772a46080fb265e67c7f43b36.tar.xz
nq-8cf40887c7b68f0772a46080fb265e67c7f43b36.zip
nq: use shared locks when waiting for other lockfiles
The nq process itself will hold an exclusive lock on its lock file,
the other nq processes will now use a shared lock to test if the
previous queue item is still locked. By using shared locks,
multiple nq processes testing the same shared lock don't interfere
with other nq processes checking for locks.
-rw-r--r--nq.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/nq.c b/nq.c
index 5fe69bf..8043fe5 100644
--- a/nq.c
+++ b/nq.c
@@ -285,11 +285,11 @@ wait:
 			if (fd < 0)
 				continue;
 
-			if (flock(fd, LOCK_EX | LOCK_NB) == -1 &&
+			if (flock(fd, LOCK_SH | LOCK_NB) == -1 &&
 			    errno == EWOULDBLOCK) {
 				if (tflag)
 					exit(1);
-				flock(fd, LOCK_EX);   /* sit it out.  */
+				flock(fd, LOCK_SH);   /* sit it out.  */
 			}
 
 			fchmod(fd, 0600);
@@ -317,7 +317,7 @@ again:
 			if (fd < 0)
 				continue;
 
-			if (flock(fd, LOCK_EX | LOCK_NB) == -1 &&
+			if (flock(fd, LOCK_SH | LOCK_NB) == -1 &&
 			    errno == EWOULDBLOCK) {
 				if (tflag)
 					exit(1);
@@ -333,7 +333,7 @@ again:
 		if (*newestlocked) {
 			int fd = openat(dirfd, newestlocked, O_RDWR);
 			if (fd >= 0) {
-				flock(fd, LOCK_EX);   /* sit it out.  */
+				flock(fd, LOCK_SH);   /* sit it out.  */
 				close(fd);
 			}
 			rewinddir(dir);