about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-12-15 21:37:16 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-12-15 21:37:16 +0100
commit9cf44c27876b3236de12fa60ff9d207f02328aa1 (patch)
tree3b5b06f54715fe5e030866abbd5417c2e040ecaf
parent6f0d1e5f44aeadc9d81b1a7a38819f7c2cb85688 (diff)
downloadnq-9cf44c27876b3236de12fa60ff9d207f02328aa1.tar.gz
nq-9cf44c27876b3236de12fa60ff9d207f02328aa1.tar.xz
nq-9cf44c27876b3236de12fa60ff9d207f02328aa1.zip
nq: open lock files read-only when we don't write into them
flock(fd, LOCK_EX) should still work.
-rw-r--r--nq.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/nq.c b/nq.c
index 985c165..10ae988 100644
--- a/nq.c
+++ b/nq.c
@@ -313,9 +313,9 @@ wait:
 			int fd;
 
 			if (strchr(argv[i], '/'))
-				fd = open(argv[i], O_RDWR);
+				fd = open(argv[i], O_RDONLY);
 			else
-				fd = openat(dirfd, argv[i], O_RDWR);
+				fd = openat(dirfd, argv[i], O_RDONLY);
 			if (fd < 0)
 				continue;
 
@@ -347,7 +347,7 @@ again:
 			    strlen(ent->d_name) < sizeof(newestlocked)))
 				continue;
 
-			int fd = openat(dirfd, ent->d_name, O_RDWR);
+			int fd = openat(dirfd, ent->d_name, O_RDONLY);
 			if (fd < 0)
 				continue;
 
@@ -365,7 +365,7 @@ again:
 		}
 
 		if (*newestlocked) {
-			int fd = openat(dirfd, newestlocked, O_RDWR);
+			int fd = openat(dirfd, newestlocked, O_RDONLY);
 			if (fd >= 0) {
 				flock(fd, LOCK_SH);   /* sit it out.  */
 				close(fd);