about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDuncan Overbruck <mail@duncano.de>2021-03-01 00:48:20 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-03-13 16:27:55 +0100
commit4f92a29b943e5d7906b884009758627bc7c3376b (patch)
tree3405b8f4a8685651935989933de0865c03e58aa2
parent8cf40887c7b68f0772a46080fb265e67c7f43b36 (diff)
downloadnq-4f92a29b943e5d7906b884009758627bc7c3376b.tar.gz
nq-4f92a29b943e5d7906b884009758627bc7c3376b.tar.xz
nq-4f92a29b943e5d7906b884009758627bc7c3376b.zip
fq: use shared locks to avoid holding exclusive locks for a split second
-rw-r--r--fq.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/fq.c b/fq.c
index ebfe6f8..a61240f 100644
--- a/fq.c
+++ b/fq.c
@@ -43,7 +43,7 @@ char buf[8192];
 static int
 islocked(int fd)
 {
-	if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
+	if (flock(fd, LOCK_SH | LOCK_NB) == -1) {
 		return (errno == EWOULDBLOCK);
 	} else {
 		flock(fd, LOCK_UN);
@@ -207,7 +207,7 @@ main(int argc, char *argv[])
 				if (nflag && islocked(fd))
 					break;
 
-				if (flock(fd, LOCK_EX | LOCK_NB) == -1 &&
+				if (flock(fd, LOCK_SH | LOCK_NB) == -1 &&
 				    errno == EWOULDBLOCK) {
 #if defined(USE_INOTIFY)
 					/* any inotify event is good */